We can create an undefined variable by giving it a name, but no value in source
let favoriteSandersonCharacter; // undefined
console.log(typeof favoriteSandersonCharacter); // "undefined"However if we never create the name, it’s “un_declared_”, and undeclared variables actually throw an error (so don’t do this):
console.log(favoriteRothfussCharacter); // ReferenceError: favoriteRothfussCharacter is not definedThe worst part is that the undeclared variable error actually says “not defined”
As an aside, you can use const to declare a variable that is assigned to undefined, but you wouldn’t be able to set its value later, so why would you want to?
const favoriteSandersonCharacter; // SyntaxError: missing = in const declaration
const favoriteSandersonCharacter = undefined; // undefined