0

If I write:

let x = 10;
let y = 20;

console.log(`Okay this is the answer: ${x+y}`);

The result that I get is:

Okay this is the answer: 30
=> undefined

let x = 10;
let y = 20;

console.log(`Okay this is the answer: ${x+y}`);

I don't understand what this => undefined means in the result displayed in the console.

Note: Although the snippet given above doesn't show => undefined, if we run the code in browser's console or in repl.it, it is shown.

Sagun Raj Lage
  • 2,326
  • 2
  • 18
  • 28
  • 1
    Where did you get undefined? We don't see it – Just code Dec 05 '18 at 04:15
  • your code is okay. i don't understand the error you have said. – david Dec 05 '18 at 04:16
  • 1
    I've edited the question. Please try it in your browser or in repl.it. – Sagun Raj Lage Dec 05 '18 at 04:16
  • @SagunRajLage If you don't log anything it still returns `undefined` in the console. I believe that it is just printing out the `return` value at the end. But since you don't return anything it just prints undefined. Eg: take a look at [this](https://repl.it/repls/ChubbySophisticatedBotany) example, at the end I `return 0` and that is what is printed – Nick Parsons Dec 05 '18 at 04:18
  • Your premise as stated in the question title is flawed. This isn't happening because you used a template literal; This is happening because of the way that the browser console works. – Claies Dec 05 '18 at 04:20

0 Answers0