Please enable JavaScript.
Coggle requires JavaScript to display documents.
Javascript - Coggle Diagram
Javascript
next gen Javascript
Classes
class Human {
constructor() {
this.gender = 'male'
}
printGender() {
console.log(this.gender)
}
}
class Person extends Human {
constructor() {
super();
this.name = 'max'
this.gender = 'famale' //can be overwrite
}
printName() {
console.log(this.name)
}
}
const person = new Person();
person.printName();
person.printGender();
ES7
class Human {
gender = 'male'
printGender = () => {
console.log(this.gender)
}
}
class Person extends Human {
name = 'max'
gender = 'famale' //can be overwrite
printName = () => {
console.log(this.name)
}
}
const person = new Person();
person.printName();
person.printGender();
Operator
Spread Operator ...
used to split up array elements OR object Properties
const newArray =[...oldArray,1,2] //append array 1 and 2
const numbers =[1,2,3]
const newNumbers=[...numbers,4]
const newNumbers2=[numbers,4]
console.log(newNumbers) //[1,2,3,4]
console.log(newNumbers2)//[[1,2,3],4]
const newObject={...oldObject,newProp:5}
// create a propertity as value 5
const person = {
name: 'max'
}
const newPerson = {
...person,
age: 28
}
console.log(newPerson)
Rest Operator
used to merge a list function arguments into an array
function sortArgs(...args){retuen args.sort()}
const filter = (...args) => {
return args.filter(el => el === 1)
}
console.log(filter(1, 2, 3))
Destructuring
Easily extract array elements or object properties and store them in variables
Array
const numbers=[1,2,3];
[num1,num2]=numbers;
console.log(num1,num2);//1,2
[num1,,num3]=numbers;
console.log(num1,num3);//1,3
Object
{name}={name:'Max',age:28};
console.log(name); //max
console.log(age);//undefined
Data assign
Reference {object} and [array]
const person ={ name:'Gordon'};
const secondPerson= person;
console.log(secondPerson)
person.name ='change person name-object and array is a pointer/Reference type ';
console.log(secondPerson)
advance
const person ={ name:'Gordon'};
const secondPerson= {...person};
console.log(person,secondPerson)
secondPerson.name='change person name-object and array is a pointer/Reference type ';
console.log(person,secondPerson)
const numbers=[1,2,3]
const doubleNumbers=numbers.map((num)=>{return num*2})
console.log(numbers,doubleNumbers)
Primitive
let num1= 10;
let num2=num1;
console.log(num1,num2);
num1=20;
console.log(num1,num2);//num2 result is 10
test url
JS Bin
jsfiddle
autocomplete with CTRL+Space