+ 1

Replacing the 'var' keyword with 'let' keyword will cause an error in this situation.what is the resson of that error?

var y = 3; console.log(y); //3 let y = 3; console.log(y); //syntaxError:unexcepted identifier

15th Aug 2019, 8:37 AM
Safaa Alnabhan
Safaa Alnabhan - avatar
7 ответов
+ 4
Safaa Alnabhan JavaScript is case sensitive. Meaning that when a variable is defined assigning another value returns error. In your case the unexpected identifier is the (let) Since you have already assigned 3 to variable y, you can't assign another value to the same.
15th Aug 2019, 8:41 AM
Jella
Jella - avatar
+ 2
Maybe you wrote "Iet" through "i" - large ("I")? Need to write through "L" - small ("l") - looks the same.☺
15th Aug 2019, 10:09 AM
Solo
Solo - avatar
+ 2
let is ES6 syntax preventing redeclaration of the same variable name. When var y is creating a window.y in the global scope, let y will raise an Exception since window.y already exists. https://code.sololearn.com/Wu1zyWlTqitX/?ref=app Read this for more differences between let and var : https://code.sololearn.com/WdGAFeNRAe9M/?ref=app https://code.sololearn.com/Wyr76080kKxS/?ref=app
15th Aug 2019, 10:23 AM
Gordon
Gordon - avatar
+ 1
These are two different piece of code The code is like var y=3; console.log(y); When replacing var with let it causes an error .. we defined the variable once but when we define it with var it works but doesn't work with let, let and console.log(); in the same scope, why does it cause an error
15th Aug 2019, 8:47 AM
Safaa Alnabhan
Safaa Alnabhan - avatar
+ 1
This is the whole question .. it is a queson in js quizes
15th Aug 2019, 9:32 AM
Safaa Alnabhan
Safaa Alnabhan - avatar
+ 1
To accurately answer your question you need to read the task in challenge. P.S: "Perhaps this is a mistake in the challenge itself, this unfortunately also happens."
15th Aug 2019, 10:06 AM
Solo
Solo - avatar
0
It can’t be, everything should work. P.S: "Show the whole code".
15th Aug 2019, 9:28 AM
Solo
Solo - avatar