ES6 let – const
بعد التحديثات الجديدة لجافا اسكربت اصبحت اللغة اقوي باختبارات اكثر ليكون الكود المراد انشائة اكثر دقة و هنا سنبدء التحدث على اول تحديث هام و معرفة فرق ما بين كلا من let and const و لماذا هم في غاية الاهمية توكلنا على الله
var VS let – const
// var global // let block scope var a = 1; let b = 2; if(a === 1){ var a = 11; let b = 22; //console.log(a); //console.log(b); } //console.log(a); //console.log(b); function withVar(){ var x = 1; if(true){ var x = 2; console.log(x); } console.log(x); } //withVar(); function withLet(){ const x = 1; if(true){ const x = 2; console.log(x); } console.log(x); } //withLet(); const note = 5; //note = 4; //console.log(note); const my_array = []; //my_array = ['b']; my_array.push('a'); my_array.push('b'); my_array.push('c'); my_array.push('d', 'f', 'g'); //console.log(my_array); const my_obj = {'key': 'value'}; //my_obj = {'otherKey': 'otherValue'}; my_obj.key = 'otherKey'; my_obj.value = 'otherValue'; console.log(my_obj);