example of javascript object

Example 1: object literal javascript

// Object literals are defined using the following syntax rules:
// A colon separates property name from value.
// A comma separates each name-value pair from the next.
// There should be no comma after the last name-value pair.

// If any of the syntax rules are broken, such as a missing comma or colon or curly brace,
// an error will be thrown.

var myObject = {
    sProp: 'some string value',
    numProp: 2,
    bProp: false
};

Example 2: javascript object

const object = {
  something: "something";
}

Example 3: 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) // 42