object js example
Example 1: creating an object javascript
let obj = {
name:"value",
num: 123,
foo: function(){}
}
Example 2: objects in javascript
let object = {
'key1': 'value1',
'key2': 'value2',
'keyn': 'valuen',
};
console.log(object);
Example 3: js obj
var obj = {my:"sql", nice:[69, 420]};
obj.my
obj.nice
Example 4: js object.create example
function userCreator (name, score) {
const newUser = Object.create(userFunctionStore);
newUser.name = name;
newUser.score = score;
return newUser;
};
const userFunctionStore = {
increment: function() {
this.score++;
},
login: function() {
console.log("Logged in!");
}
};
const user1 = userCreator("Justin", 41);
const user2 = userCreator("Rainer", 5);
user1.increment();
console.log(user1.score)