var oldVariable='shadhin';
let NewVariable="Monir";
console.log(oldVariable);
console.log(NewVariable);
const variableCanotChange=10;
console.log(variableCanotChange);
//variableCanotChange=20;
console.log(variableCanotChange);
function oldfunction(para) {
console.log(para);
}
let newFunction=(para)=>{
console.log(para);
}
//if only one parameter
newFunction=para=>{
console.log(para);
}
//if no parameter
newFunctionWithoutPara=()=>{
console.log("without para");
}
//multiple parameter
functionMultiplePara=(name,age)=>{
console.log(name,age);
console.log(age*2);
}
//function with short form
const shortFun=para=>para*2;
oldfunction("shadhin");
newFunction("monir1");
newFunction("monir2");
newFunctionWithoutPara();
functionMultiplePara('shadhin',10);
console.log(shortFun(20));
class a {
constructor(){
this.age=20;
}
print_age(){
console.log(this.age)
}
}
class b extends a{
constructor(){
super();
this.age=27;
this.name='shadhin';
}
print_name(){
console.log(this.name);
}
}
const obj=new b();
obj.print_name();
obj.print_age();
class a {
age=20;
print_age=()=>{
console.log(this.age)
}
}
class b extends a{
age=27;
name='shadhin';
print_name=()=>{
console.log(this.name);
}
}
const obj=new b();
obj.print_name();
obj.print_age();
//Spread operator
const numbers =[1,2,3];
const newNumbers=[...numbers,4];
console.log(newNumbers);
const obj={
name:'shadhin'
}
const newobj={
...obj,
age:28
}
console.log(newobj);
//Rest
const sortFun=(...arg)=>{
return arg.sort();
}
console.log(sortFun(2,4,1,6,8));
const numbers=[1,2,3];
[num1,,num3]=numbers;
console.log(num1,num3);
- variable copy (Array and Object Reference type)
No comments:
Post a Comment