Some Javascript Confusing Element A React Developer Should know

There are some confusing topics in Javascript. Here we discuss some of them. Let’s start together.

Truthy and Falsy:

The following values are falsy always:

  • false
  • 0 (zero)
  • '', "", ``(Empty string)
  • null
  • undefined
  • NaN

If they are put as a parameter in any logical condition that statement check/return false always.

Boolean(NaN) // false

Everything else is truthy.

Like:

  • '0' (a string with a value 0)
  • 'false' (a string with the text “false”)
  • [] (empty array)
  • {} (empty object)
  • function(){} (a function without any return or parameter)

So use those values with special care because a small mistake in syntex can change the overall result of the program.

--

--

Mohammad Anisul Islam

Software Engineer || Full Stack Developer || Technical Writer || Speaker