1 2 3 4 5 6 7 8 |
function getSomething() { return { name: "rick" } } console.log(getSomething()); |
IN this situation, you’ll get undefined because a break after the keyword return makes JS gives you an automatic semicolon. It thinks that because you have a bracket on the next line, this is a line-break and will automatically insert a semicolon for you.
To remedy this do this:
1 2 3 4 5 6 7 |
function getSomething() { return { // always put starting brackets after return name: "rick" } } console.log(getSomething()); // rick |