Created
February 21, 2018 16:39
-
-
Save thelbouffi/248e3866399b4618d8335e0fee300c78 to your computer and use it in GitHub Desktop.
Chrome or node.js displays “undefined” on the console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The JavaScript functions always return something. If you don't specify something to return in the function then | |
// 'undefined' is returned by default | |
// So, console.log() will always return 'undefined' on node and chrome because the function doesn't return anything | |
let x; | |
let y = 3; | |
console.log(y); | |
// this console.log will return | |
// 3 | |
// undefined | |
// 3 is the log of y and undefined is the return of the function console.log() | |
// to be more sure let's create a function that do the same job of console.log() but has a return | |
funcrtion print(a){ | |
return a; | |
} | |
print(y); | |
// this function will return only 3 without undefined | |
// 3 | |
// 3 is the value of y and print make a return which it's not undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment