Investigate value types

It’s your first investigation 🥳 . Time to play and have fun!

Read the code below, and before you run it, see if you can guess what value types would be logged for each.

The null dilemma

You might be surprised that null is shown as an object. If that is the case then what would do you think would be logged to the console?

As you can see, nothing gets logged because an error is thrown!

null is clearly not an object, despite what typeof returns. This is a JavaScript oddity that was added to the language very early on and has been tricky to remove since.

Value comparison and coercion

Guess whether each log statements will be true or false. Why do you think there is a difference for one of them?

Variables

Let's take a look at the behaviour of let...

What about const?

Did nothing appear after you clicked "Run"?

The code didn't even run. The statement const productId; already threw an error, because if you assign const to undefined, it's going to remain undefined FOREVER. It's basically the JavaScript engine asking, "what's the point?" 🤷‍♀️

That's enough investigation for now, let's start visualizing!