Stuck on a variables questions

Stuck on this question "Create an undefined variable named valueless. Log the result to the console.’

What am I supposed to do?

And undefined variable is one that is declared (eg. with var or let) but for which there is no value set.

var valueless;


let valueless;

If we log this variable, we get,

console.log(valueless);    // ->  undefined

Some tutorials equate declared with defined but in JavaScript there is a definite distinction.

console.log(myVar);   // ->  ReferenceError: myVar is not defined

We can see where there might be some confusion, ‘is not defined’ is right there in the error message. However, since it is undeclared, it raises a reference error.

let myVar;

console.log(myVar);   // ->  undefined

Now we see that the variable has been allocated memory, but has no associated value so the reserved memory is empty.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.