const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const returnedTarget = Object.assign(target, source);
// using object.assign method first object will be simply concatenated to second one
also we can write empty {} brackets and set it empty object as a first argument
// rest operator
let {...method2} = car
// let {model, ...rst} = car
// let {model, ...car} = {year:"2017", ...car}
rest operator is allows us to skip some propoerties..
we can also use it with spread operator and it will more useful because it can add or update properties at the same time// spread operator
let method1 = {...car}
// method1 === car // false
// method1.model = "F150"
// let sprd = {...car, color: "black", model:"ranger"}
if the comparison returns false so it cloned successfully because they will refer to a different location on memory. So we can add or update properties with another parameters after spread operator.. var parents = ["mom", "dad"]
var children = ["mike", "jenny"]
var family = parents.concat(children);
Result of family variable:
["mom", "dad", "mike", "jenny"]
var family = ["mom", "dad", "mike", "jenny"]
var fstr = family.join();
output:
fstr = "mom,dad,mike,jenny"
function hello() { alert('Hi there!'); }
setTimeout(hello, 5000)
or
setTimeout( function() { alert('Hi there!'); }, 5000 )
Configurable Attribute
: Specifies whether the property can be deleted or changed.
Enumerable
: Specifies whether the property can be returned in a for/in loop.
Writable:
Specifies whether the property can be changed.var christmasList = {mike:"Book", jason:"sweater" }
then delete some property with delete keyword
delete christmasList.mike; // deletes the mike property
var school = {schoolName:"MIT"};
console.log("schoolName" in school); // true because schoolName is an own property on the school object
console.log("schoolType" in school); // false because because we did not define a schoolType property on the school object
// Prints true because the school object inherited the toString method from Object.prototype.
console.log("toString" in school); // true