+ 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
7 Respuestas
+ 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.
+ 2
Maybe you wrote "Iet" through "i" - large ("I")?
Need to write through "L" - small ("l") - looks the same.☺
+ 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
+ 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
+ 1
This is the whole question .. it is a queson in js quizes
+ 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."
0
It can’t be, everything should work.
P.S: "Show the whole code".