Skip to content

Instantly share code, notes, and snippets.

@aaronfrost
Last active August 29, 2015 14:06
Show Gist options
  • Save aaronfrost/d815545ccf196e0bf07c to your computer and use it in GitHub Desktop.
Save aaronfrost/d815545ccf196e0bf07c to your computer and use it in GitHub Desktop.
Do I Call This "Undeclared"?
var a;
console.log(a); //Logs 'undefined'
console.log(b); //ReferenceError: 'b' is not defined
/**
* Neither are defined, but only the undeclared variable gets an 'undefined' error.
*
* So, is the correct idiom 'undeclared' when referring to an instruction that will throw
* a ReferenceError because it wasn`t declared? Or is there another idiom that I should use?
*
* I have heard people say "There is no 'undeclared' in JavaScript", so I am not sure what to call it.
*
* What Say Ye?
* /
@mzabriskie
Copy link

I have always used undeclared to describe this.

Straight from MDN:

The variable statement declares a variable, optionally initializing it to a value.
Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var

From that I consider a declared as a variable, but with an undefined value. Ergo b would be undeclared.

@onaclov2000
Copy link

I'm not a deep JS developer but I would personallycall it 'unknown'.
Here's why. It hasnt been defined what it isAND what its value is. Undeclared to me implies there is data but you just dont know the type (internally) yet.
In this case both scenarios are gone, if you assigned b to some crazy 'thing' that JavaScript doesn't understand wtf is going on, you may consider undeclared.... But what the heck do I know

If there is documentation out there referring to undeclared, ive never seen it so tgose are my opinions solely based on what i see in front of me.

$.02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment