In javascript, what happens below this condition? (3 == '3')

Asked

Viewed 33 times

0

In javascript, what happens below this condition?

(3 == '3')

  • In short, Javascript implicitly converts the data. Do a test, try to put in the console the following operations: 3 * '4'; true == 1; !!null

  • Javascript has weak typing, that is, it tries to promote types to make the operation work. In this case, if one type is numeric and the other is string, the string is converted to number. If you want to avoid this conversion, use the == operator, which makes the "strong" comparison, where 3 is different from '3'.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.