DEV Community

PUSHAN VERMA
PUSHAN VERMA

Posted on

Learnig and Revising Js , Day 1

Hi guys , just sharing what i have learnt , may be you will find all these informative,

These are some basic concepts of javascript , I will be sharing everything that i'll be doing here , Like if you like the content , See a have a good day !!

//๐Ÿ‘‰ Objects is known to as "hashmap in java" and in "python it is called as dictionary"

// object is a group of key , value pair

//key: value --> propert
//key: function --> method

// key can be string/integr and same ways value also

let cap={
name:"Steve",
lastName:"Rogers",
address:{
city:"Manhattan",
state:"New York"
},
age:35,
isAvenger:true,
movies:["First Avenger","Winter Soldier","Civil War"],
sayHi: function()
{
console.log("Cap says HI ");
}
};
//๐Ÿ“Œget (getting keys)
// console.log(cap.name);
// console.log(cap.age);
// console.log(cap.movies[1]);
// cap.sayHi();

//๐Ÿ“Œset /update
// console.log("cap",cap);
// cap.age =36;
// cap.isAvenger=false;
// cap.friends=["Tony","Bruce","Peter"];
// console.log("---------------------------------------");

//๐Ÿ“Œdelete
// delete cap.address;
// console.log("cap",cap);

//๐Ÿ‘‰diffrence between .(dot) & -->(cap.age and cap[propkey] ,where propkey="age")
// (cap.age gives values direcet , but cap[propkey] gives values through varibale )
let propkey="age"
console.log(cap[propkey]);
console.log(cap["age"]);

//๐Ÿ“Œfor in loop
for(let key in cap)
{
console.log(key," : ",cap[key]);
}

//๐Ÿ‘‰ it basically internally makes its as cap["name"],cap["lastname"],cap["address"] everytime and gives the answer,
// its just the other way of writing ,nothing else

// ๐Ÿ“Œif we want to print a key , i.e not present in object , then we get undefined for that

console.log(cap.xyz);

Top comments (0)