-3

Out of curiosity, why does writing console.log("hello") inside console return undefined?

Is it for the same reasons in defining void function in C?

enter image description here

Vincent Tang
  • 3,758
  • 6
  • 45
  • 63
  • 3
    Because `console.log` returns `undefined`. – Teemu Jan 24 '18 at 15:58
  • 2
    All JS functions have a return value. When one isn't explicitly defined, it returns `undefined` automatically. So either `console.log()` explicitly returns that value, or it gives no explicit return value and gets that as the default. –  Jan 24 '18 at 16:05

1 Answers1

1

The console.log just write a text and return with undefined. If you create a function, add a returning value, there will be not undefined, it will returns with the added value. Example:

function writer(){
    console.log("write new line");
    return "ok";
}

If you call the writer() that the output is "ok" in new line after "write new line".

DiabloSteve
  • 431
  • 2
  • 13