• Home
  • Is JavaScript most confusing programming language?

Is JavaScript most confusing programming language?

So JavaScript is most popular programming language this days for developers. But let me show you some fun examples that makes no sense. Yo can test examples inside your developer tools.

8 + 8

Simple sum of this two numbers will give me 16. OK… this is not weird. But let’s go further

8 + '8'

It gives me ’88’. This makes sense. Right?

What about this

'8' + 8

This is also ’88’. More sense that previous one ….

But if we check

8 == '8'

we will get true … 🙂

Now comes fun part 🙂 Space is important.

8 + + '8'

Now what. This is 16 … How?

What about this ….

'8' - - '8'

This is also 16 … eh

NaN === NaN

gives me false … OK

{} + [] === 0
[] + [] === ''
[] * 1 === 0
false + 1 === 1

These are all true … OK 🙂

typeof NaN === 'number'

🙂 🙂 🙂  … this will give me true

But this is one way to look at JavaScript. These examples can be explained and it needs deeper understanding of something called value type check so from that point of view above examples are correct ( for example, == doesn’t check value type, === does check value type)

Tags:

Copyright by Kristijan Klepač 2018