When I run \"var variable = true;\" in chrome console I get \"undefined\" returned:
> var variable = true;
undefined
But when I run with
I'd like to point out, that the answer provided by kennytm should be the accepted answer, at least for pedagogical purposes. The accepted answer doesn't answer why this is the case or provide deeper understanding.
Like the null value in JavaScript, undefined indicates absence of value, but in a much deeper way. The following should be taken as complimentary to the above-mentioned answers:
undefinedis the value of variables that haven't been initialized and the value you get when you query the value of an object property or array element that doesn't exist. This value is also returned by functions that have no return value, and the value of function parameters for which no argument is supplied.undefinedis a predefined global variable (not a language keyword like null) that is initialized to the undefined value.You might consider
undefinedto represent a system-level, unexpected, or error-like absence of value andnullto represent program-level, normal, or expected absence of value.-- Flanagan, David. JavaScript: The Definitive Guide: Activate Your Web Pages (Definitive Guides) . O'Reilly Media. Kindle Edition.
Also, makes sure to check out both the accepted and the second most voted answer for further reference: Chrome/Firefox console.log always appends a line saying undefined