What is let in java script. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is let in java script.

8th Sep 2018, 1:52 PM
MILSON
MILSON - avatar
4 Answers
+ 1
In ES6 there is 3 form of declarate a variable: let, var, const. A basic different is let to local scopo, var to all scopo and const can't to be changed. Look: <script> let a = 5; var b = 1; const c = 3; for(var i = 0; i < 7; i++){ if(i === 2){ let d; return d = i; } } try{ c = 4; // const can not change it }catch(e){ console.log(e); } console.log(a,b,c,d); // d is not defined // d just can seen in if </script>
20th Sep 2018, 1:45 AM
Mr Genesis
Mr Genesis - avatar
+ 5
It's a block scope variable since ECMAScript 2015. You can read more here https://www.w3schools.com/js/js_let.asp
8th Sep 2018, 2:18 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
let is keyword in Javascript ES6 version which is analogous to var keyword in JavaScript ES5.It is used to declare a variable.
8th Sep 2018, 7:36 PM
Mithilesh
Mithilesh - avatar
0
difference between using "let" and "var" Variables declared by "var" keyword are scoped to the immediate function body (function scope) while "let" variables are scoped to the immediate enclosing block denoted by {....} (block scope). Variable declared with var keyword can be re-declared and updated in the same scope while variable declared with let keyword can be updated but not re-declared. Variables defined with let are hoisted to the top of the block , but not initialized. This means that the block of code is aware of the variable, but it cannot be used until it has been declared. So, using a let variable before it is declared will result in a ReferenceError. http://net-informations.com/q/js/let.html
24th Nov 2021, 4:54 AM
creigmalta