var a = 10; let b = 20; const c = 40;
I was playing around with above syntax, and tried something silly.
var let = 100; var const = 100;
And. the result was surprising.
let variable was successfully created, but for const I got an syntax error.
You might be thinking why defining
let as a variable did not give syntax error. I was thinking the same.
You might be curious to know why it happened. So, here goes your answer:
So From above list, as
let is reserved only when strict mode is used. So I tried below code:
"use strict"; var let = 100;
Now finally, it gives error when
let is used as a identifier.
In same way we can use below keywords an identifier.
In strict mode it will give syntax error.
*Note: * It is good idea to always give you identifier a meaningful name. Do not use reserved keyword as an identifier.
What's you thoughts, let me know in the comments.