I've seen code where a ternary operator is used to check whether or not a variable has been declared, and declare it if it has not been. For example:
var num = (typeof num === 'undefined' ? 1 : num);
console.log(num); //1
However, this does not work when using 'let' instead of 'var':
let num = (typeof num === 'undefined' ? 1 : num); //Uncaught ReferenceError: num is not defined
I know that compared to 'var', 'let' has block scoping and prevents redeclaration. I'm unsure how this would cause the ReferenceError in the case above. Could anyone shed some light as to what's going on here? Thanks!