Typeof Operator

Can someone explain why the second newVariable is just entered newVariable = 1 instead of let newVariable = 1 ??


Hey @pbk wrlcome to the forums.

It is like this because let const and `var’ are only for decelerations when you make the variable.

You can only declare the variable once, but then you can change the value of the variable is it was declared using let or var.

This works:

let x = 5;  // variable declared
x = 6; // new value assigned to variable 

This fails:

let x = 5; // variable declared
let x = 6; // variable declared again
1 Like

It’s because the let keyword doesn’t allow you to re-declare a variable, had you used the var keyword then that would have been possible.
Since you have already written let newVariable on the first line, using let again with that variable would mean that you are re-declaring it and that would throw an error

Thanks everyone for your responses! Makes sense now :slight_smile: