Stuck on a variables questions


#1

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

What am I supposed to do?

https://www.codecademy.com/courses/learn-javascript-introduction/lessons/variables/exercises/unset-variable?action=lesson_resume&course_redirect=introduction-to-javascript


#2

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

var valueless;

or

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.


#3

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