////////////////**************OBJECTS IN JS **********////////////////////
//// singleton (all constructors are singleton)
// object literals are not singleton
const mySym = Symbol("key1")
const jsUser ={
name: "hitesh", "full name": "Hitesh chaudhary",
age: 18 ,
[mySym] : "mykey1",
location: "jaipur ",
email: "den@gmail.com",
isLoggedIn: false,
lastLoginDays: ["monday","saturday"]
}
console.log(jsUser.email); //den@gmail.com
console.log(jsUser["email"]);//den@gmail.com
console.log(jsUser["full name"]);//Hitesh chaudhary
console.log(jsUser[mySym]);// mykey1
jsUser.email = "chatgpt@gmail.com " /// editing by just overriding it
console.log(jsUser.email); //chatgpt@gmail.com
// Object.freeze(jsUser); // it will lock all the value assinged
// function in js
jsUser.greeting = function() {
console.log("hello js user");
}
console.log(jsUser.greeting()); // hello js user
console.log(jsUser.greeting); // [Function (anonymous)]
jsUser.greeting2 = function() {
console.log(`hello js user ${this.name}`);
}
console.log(jsUser.greeting2()); // hello js user hitesh
console.log(jsUser.greeting2); // [Function (anonymous)]
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter