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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Mohammad Anisul Islam
Mohammad Anisul Islam

Written by Mohammad Anisul Islam

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

No responses yet

Write a response