Looks like you're missing a closing curly brace on your submitInformation function: ```Javascript var textAnswer = document.getElementById("text-1"); var submitButton = document.getElementById("button-1"); var submitInformation = function(){ console.log(textAnswer.value); } // Answer from Paul Yabsley on teamtreehouse.com
🌐
W3Schools
w3schools.com › jsref › jsref_undefined.asp
W3Schools.com
The undefined property indicates that a variable has not been assigned a value, or not declared at all.
🌐
Dmitri Pavlutin
dmitripavlutin.com › 7-tips-to-handle-undefined-in-javascript
7 Tips to Handle undefined in JavaScript
March 23, 2023 - One of the nice features of const is that you must assign an initial value to the variable const myVariable = 'initial'. The variable is not exposed to the uninitialized state and accessing undefined is impossible.
Discussions

What is the difference between null and undefined in JavaScript? - Stack Overflow
If I want to have a variable that has no value in the beginning, I write "... = null", eg "myvar = null". This way - when I mistype "if (myxar == null) {...}" - the if block is not executed. I don't have this advantage with undefined: myvar = undefined; myvar = 4; if (typeof myxar == "undefined") ... More on stackoverflow.com
🌐 stackoverflow.com
lodash - Javascript how to set null/undefined values in an Object to an empty string - Stack Overflow
I have an object where some fields have a value of null or undefined. Is there a nice quick way to change these values to an empty string '' using Javascript or Lodash? Example input: { a: '23'... More on stackoverflow.com
🌐 stackoverflow.com
How can I determine if a variable is 'undefined' or 'null'?
As for instanceof, if the questions is "IS THIS VARIABLE NULL OR UNDEFINED?" (perhaps you want the value to be null or undefined...) you cannot ascertain that with instanceof, except by checking that the value isn't an instance of any other type, which is crazy. More on stackoverflow.com
🌐 stackoverflow.com
How can I check for "undefined" in JavaScript? - Stack Overflow
See: How to check for undefined ... ‘undefined’ in javascript ... That "duplicate" is about object properties, so some of the answers don't apply very well to this question, asking about variables. ... If you are interested in finding out whether a variable has been declared regardless of its value, then using ... More on stackoverflow.com
🌐 stackoverflow.com
Looks like you're missing a closing curly brace on your submitInformation function: ```Javascript var textAnswer = document.getElementById("text-1"); var submitButton = document.getElementById("button-1"); var submitInformation = function(){ console.log(textAnswer.value); } // Answer from Paul Yabsley on teamtreehouse.com
🌐
Wikipedia
en.wikipedia.org › wiki › Undefined_value
Undefined value - Wikipedia
1 week ago - In computing (particularly, in programming), undefined value is a condition where an expression does not have a value semantically correct in the object language, although it is syntactically correct. An undefined value must not be confused with empty string, Boolean "false" or other "empty" ...
🌐
Codereadability
codereadability.com › how-to-check-for-undefined-in-javascript
How to check for undefined in JavaScript
September 21, 2015 - When a variable is declared without being assigned a value its initial value is undefined. How do you check if a value is undefined in JavaScript? The short answer In modern browsers you can safely compare the variable directly to undefined: if (name === undefined) {...} Some people argue against ...
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › undefined
undefined - JavaScript | MDN
January 9, 2021 - In all non-legacy browsers, undefined is a non-configurable, non-writable property. Even when this is not the case, avoid overriding it. A variable that has not been assigned a value is of type undefined. A method or statement also returns undefined if the variable that is being evaluated does ...
🌐
Rosetta Code
rosettacode.org › wiki › Undefined_values
Undefined values - Rosetta Code
September 9, 2025 - There is no "undefined" value as every instruction that is capable of altering the contents of a register will set the value of that register equal to some number between 0 and 0xFFFFFFFF.
🌐
Medium
medium.com › technoetics › difference-between-null-undefined-and-not-defined-in-javascript-3a52a62894b
Difference between null, undefined and not defined in javascript | by Saurabh Mhatre | CodeClassifiers | Medium
October 22, 2018 - Null essentially represents a non-existent or an empty value i.e. we explicitly tell javascript interpreter that the variable has no value. ... A not defined is a variable which is not declared at a given point of time with declaration keyword ...
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › javascript-null-and-undefined
Difference between null and undefined in JavaScript
Here you will learn what is null and undefined in JavaScript and what is the difference between them. A null means the absence of a value. You assign a null to a variable with the intention that currently this variable does not have any value ...
🌐
freeCodeCamp
freecodecamp.org › news › javascript-check-if-undefined-how-to-test-for-undefined-in-js
JavaScript Check if Undefined – How to Test for Undefined in JS
November 7, 2024 - An undefined variable or anything without a value will always return "undefined" in JavaScript. This is not the same as null, despite the fact that both imply an empty state. You'll typically assign a value to a variable after you declare it, ...
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-determine-if-variable-is-undefined-or-null-in-javascript.php
How to Determine If Variable is Undefined or NULL in JavaScript
In simple words you can say a null value means no value or absence of a value, and undefined means a variable that has been declared but no yet assigned a value.
🌐
Flexiple
flexiple.com › javascript › undefined-vs-null-javascript
Undefined vs Null - Javascript - Flexiple
March 10, 2022 - Many times we often get confused on what the difference between UNDEFINED and NULL is. Simply put, undefined means a variable has been declared but has not yet been assigned a value. undefined is a type by itself (undefined).
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript undefined
JavaScript undefined
October 6, 2023 - And both null and undefined values represent empty values in JavaScript.
🌐
To The New
tothenew.com › home › difference between ‘null’ and ‘undefined’ in javascript
Difference Between ‘null’ and ‘undefined’ in JavaScript | TO THE NEW Blog
May 23, 2013 - 1. Declared but not defined – JavaScript assigns ‘undefined’ to any object that has been declared but not initialized or defined. In other words, in a case where no value has been explicitly assigned to the variable, JavaScript calls it ...
🌐
The Valley of Code
thevalleyofcode.com › how-to-check-undefined-property-javascript
How to check if a JavaScript object property is undefined
May 26, 2018 - In a JavaScript program, the correct way to check if an object property is undefined is to use the typeof operator. typeof returns a string that tells the type of the operand. It is used without parentheses, passing it any value you want to check:
Top answer
1 of 16
3234

If you are interested in finding out whether a variable has been declared regardless of its value, then using the in operator is the safest way to go. Consider this example:

// global scope
var theFu; // theFu has been declared, but its value is undefined
typeof theFu; // "undefined"

But this may not be the intended result for some cases, since the variable or property was declared but just not initialized. Use the in operator for a more robust check.

"theFu" in window; // true
"theFoo" in window; // false

If you are interested in knowing whether the variable hasn't been declared or has the value undefined, then use the typeof operator, which is guaranteed to return a string:

if (typeof myVar !== 'undefined')

Direct comparisons against undefined are troublesome as undefined can be overwritten.

window.undefined = "foo";
"foo" == undefined // true

As @CMS pointed out, this has been patched in ECMAScript 5th ed., and undefined is non-writable.

if (window.myVar) will also include these falsy values, so it's not very robust:

false
0
""
NaN
null
undefined

Thanks to @CMS for pointing out that your third case - if (myVariable) can also throw an error in two cases. The first is when the variable hasn't been defined which throws a ReferenceError.

// abc was never declared.
if (abc) {
    // ReferenceError: abc is not defined
} 

The other case is when the variable has been defined, but has a getter function which throws an error when invoked. For example,

// or it's a property that can throw an error
Object.defineProperty(window, "myVariable", { 
    get: function() { throw new Error("W00t?"); }, 
    set: undefined 
});
if (myVariable) {
    // Error: W00t?
}
2 of 16
1586

I personally use

myVar === undefined

Warning: Please note that === is used over == and that myVar has been previously declared (not defined).


I do not like typeof myVar === "undefined". I think it is long winded and unnecessary. (I can get the same done in less code.)

Now some people will keel over in pain when they read this, screaming: "Wait! WAAITTT!!! undefined can be redefined!"

Cool. I know this. Then again, most variables in Javascript can be redefined. Should you never use any built-in identifier that can be redefined?

If you follow this rule, good for you: you aren't a hypocrite.

The thing is, in order to do lots of real work in JS, developers need to rely on redefinable identifiers to be what they are. I don't hear people telling me that I shouldn't use setTimeout because someone can

window.setTimeout = function () {
    alert("Got you now!");
};

Bottom line, the "it can be redefined" argument to not use a raw === undefined is bogus.

(If you are still scared of undefined being redefined, why are you blindly integrating untested library code into your code base? Or even simpler: a linting tool.)


Also, like the typeof approach, this technique can "detect" undeclared variables:

if (window.someVar === undefined) {
    doSomething();
}

But both these techniques leak in their abstraction. I urge you not to use this or even

if (typeof myVar !== "undefined") {
    doSomething();
}

Consider:

var iAmUndefined;

To catch whether or not that variable is declared or not, you may need to resort to the in operator. (In many cases, you can simply read the code O_o).

if ("myVar" in window) {
    doSomething();
}

But wait! There's more! What if some prototype chain magic is happening…? Now even the superior in operator does not suffice. (Okay, I'm done here about this part except to say that for 99% of the time, === undefined (and ****cough**** typeof) works just fine. If you really care, you can read about this subject on its own.)