0

I am following a book on Javascript and the example doesn't seem to return any value. I don't have much experience with OOP though.

I believe this is a programmatical way to create classes, but it returns undefined any way

JS console on chrome

What do you make of this?

Thank you in advance

staminna
  • 468
  • 1
  • 5
  • 26
  • 1
    _declaration_ statements (`var`, `let`, `const`, `function` and `class` statements) create what the ECMAScript specification refers to as an "empty normal completion". At the language level, that looks like an `undefined`. – Patrick Roberts Sep 19 '19 at 17:56
  • If you just call the variable you assigned the class instantiation to, it'll evaluate properly. of course console.log doesn't have a return value, it's only function is to trigger a printing side effect in the console. When you console log it, you can see it printed in the console, which means it's defined and as that value... printed in the console.... you can see it there – Jacob Penney Sep 19 '19 at 18:06
  • Thank you guys for clear explanations – staminna Sep 19 '19 at 20:14

1 Answers1

0

This is expected, variable declarations always return undefined. E.g., let a = 0, var b = 0, const c = 0.

This doesn't mean a, b, and c are undefined though.

Likewise for your example, createClass and Book aren't undefined, as seen by your console.log.

junvar
  • 11,151
  • 2
  • 30
  • 46