const showUser = () => {
const name = "Ram and Hanuman";
return name;
}
const data = showUser();
console.log(data);
const x = [1,2,3,4,5];
const y = [5,6,7,8,9,10];
const data = [...x, ...y];
console.log(data);
// Eaxmple 1
function show(...rest){
let data = rest;
console.log(data); // ["Saten Pratap", 2, "Ram", 12, "Banglore"]
}
show('Saten Pratap', 2, 'Ram', 12, 'Banglore');
// Eaxmple 2
function show(name, ...rest){
let data = rest;
console.log(name); // 'Ram'
console.log(data); [2, "Ram", 12, "Banglore"]
}
show('Ram', 2, 'Sham', 12, 'Banglore');
const users =['Ram','Sham','Hanuman'];
const [r,s,h]= users;
console.log(r); // "Ram"
console.log(s); // "Sham"
console.log(h); // "Hanuman"
const {...item} = users;
console.log(item) // { 0: "Ram", 1: "Sham", 2: "Hanuman" }
Object De-structuring
const users ={name:'Ram',city:'Ayodhya',state:'UP' };
const {name, city, state}= users;
console.log(name); // "Ram"
console.log(city); // "Ayodhya"
console.log(state); // "UP"
Props De-structuring
function show(props) {
const {name, city, state}= props;
console.log(name); // "Ramayan"
console.log(city); // "Ayodhya"
console.log(state); // "UP"
}
const data ={name:'Ramayan',city:'Ayodhya',state:'UP' };
show(data);
const data ={name:'Ram',city:'Ayodhya',state:'Uttar Pradesh' };
console.log(`My name is ${data.name} from ${data.city} ${data.state}`)
//var is global variable and window object
var data = "China"; // This is window object it can be used anywhere
//let is not global variable
let x = 10;
let x // can not redeclare and can update
//const is constant variable type
const y = 12;
let y // // can not redeclare
// Block scope
function show(){
let a = 12; // blocked scope variable,can not use outside of function
let name = 'Ram'; // blocked scope variable, can not use outside of function
console.log(a);
console.log(name);
}
//Find unique elements
var data = [1, 3, 5, 7, 9, 3, 1, 5, 11, 4, 13, 7, 11, 9, 13];
var num = [...new Set(data)];
console.log(num);;
//Example 1
(function(){console.log('My name is Saten Pratap');})(); // "My name is Saten Pratap"
//Example 2
(function(a,b){console.log(a+b);})(12,18); // 30
//Example 3
((a,b)=>{console.log(a+b);})(10,12); // 22