Difference between revisions of "Operators"
Jump to navigation
Jump to search
| Line 22: | Line 22: | ||
== Default Parameters === | == Default Parameters === | ||
function Person(first, last = ' | function Person(first, last = 'lastname'){ | ||
this.firstname = first; | this.firstname = first; | ||
this.lastname = last; | this.lastname = last; | ||
Latest revision as of 20:01, 1 December 2025
ES6 Spread Operator
ES6 Equivalent Spread Operator
const sum3 = addFourAges(...ages); // the ... means the ages array is expanded into individual components.
Join two Arrays
const arrayOne= ['hello', 'two']; const arrayTwo = ['three', 'four']; const arrayThree = [...arrayOne, ...arrayTow];
Looping through all elements and changing the color
const h = document.querySelector(h1)
const boxes = documwnt.querySelectorAll('.box');
const all = [h, ...boxes]; Array.form(all).forEach(cur=> cur.style.color='purple') // returns an array
Rest Parameter
function isFullAge(...years){
years.forEach(cur=> (216-cur)>=18);
}
isFullAge(1990,1921,1967);
Default Parameters =
function Person(first, last = 'lastname'){
this.firstname = first;
this.lastname = last;
}
Maps
New key value data structure
const question = new Map();
question.set('question', 'what is');
question.set(1,'es5);
question.set(2, 'es6');
question.set(3, 'ES2015');
question.set('correct', 3);
question.set(True, 'Correct Answer');
question.set(false, 'wrong');
// Retrieve DAta
question.get('question')
// get size
question.size;
// delete
question.delete(2);
// delete All
question.clear();
// loop
question.forEach((value,key)=> console.log(`this ${key}, and its set ot ${vlaue})
// Another Way to Loop
for(let[key, value]of question.entries()){
console.log(`this ${key}, and its set ot ${vlaue});
if(typeof(key)=== 'number'){
console.log(`Answer ${key}, and its set ot ${vlaue});
}