undefined
JS-0126That’s all we can say right now.
In JavaScript, a variable that is declared and not initialized to any value automatically gets the value of undefined. For example:
var foo;
console.log(foo === undefined); // true
It's therefore unnecessary to initialize a variable to undefined
, such as:
var foo = undefined;
It's considered a best practice to avoid initializing variables to undefined
.
var foo = undefined;
let bar = undefined;
var foo;
let bar;
const baz = undefined;