Overview ES6

// Let & Const & Block Scope
let name = "Mokhtar";
const myName = "Mokhtar"

// Arrow Functions
// on line without {} & return
let onLineFunc = ()=>"Mokhtar";
// on parameter without ()
let onParamFunc = val=>val+10
// another example
let es6Func = ()=>{
    return "I'm ES6 Function.";
}
// function with default parameters
let defParams = (val = 0){
    return val+10;
}


// Spread & Rest 
// spread
const nums = [1,2,6,9];
console.log(Math.max(1,2,5,6,7,8,9,15));
console.log(Math.max(...nums))
// rest
const Rest = (...args)=>{
    return console.log(args[0])
}
let arr = [1,2,6,9];
Rest(arr)

// Destructuring Arrays
const favos = ["ts","js"];
const [fav1,fav2] = favos; // same as fave1 = favos[0] and fav2 = favos[1]

// Destructuring Objects
const userData = {userName:"Mokhtar",userAge:34};
const {userName,userAge} = userData; // same as userName = userData.userName and userAge = userData.userAge

// تفاوت با آرایه در این است که حتما باید از نام خواص آبجکت استفاده شود که البته راه حل دارد
const {userName:theName,userAge:theAge} = userData;
console.log(theName);

// Template Literals قالب بندی متون
// بدون نیاز به شکستن خطوط
let TempText = `
    This is line one
    and my name is ${theName}
`;
console.log(TempText)