There are various types which it can be used.
var name= "shaktiman";
var age= "100";
var strength= "1000";
here we are storing the values in different variable which may cause problem further. As if we can't store values for 1000. it is quite complicated. var shaktiman={
name:"shaktiman",
age:100,
strength: 1000,
color:"blue"
}
We stored various properties in a single variable. Thus it is easier to access properties present. This is also known as the key : value pair.
we can access properties by shaktiman.name, shaktiman.strength....
If we want to store values of 50 people with same properties. So instead of creating 50 variable we can store by creating a function. we can pass properties to this function as an argument
function hero (name, age, strength, color)
{
this.name:"name",
this.age:"age",
this.strength: "strength",
this.color:"color"
}
pass values:
var shaktiman = new hero("shaktiman",10,1000,"blue")
var ironman = new hero("ironman",100,2000,"black")
we can select elements by various method
1.By Tag Name
This property gives for all elements with the particular tag name given .
document.getElementsByTagName("li")
it will give all element with tag li.2.By Class Name
This property gives all elements with the particular class name.
We can select the class of html file in the js by using
document.querySelector.
for example,
we have a class with name para. We can select this Class
para in our js file by using ".".
var paragraph = document.querySelector(".para")
here, the class is stored in the variable called paragraph.
2.By using Id
This property gives for all elements with the
particular id name given. Id is unique on every
page.
We can select the element with particular id of html file in the js by using
document.querySelector.
for example,
We have id with name input-one and we can select this
by using "#".
var inputOne= document.querySelector("#input-one")
here, the element with id input-one is stored in the
variable called inputOne.