If I have a variable x = “”
And I check for the following condition
if x != 0
Is it evaluated as false across all the browsers ?
Why is 0 treated the same as “” ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you use the
==operator JavaScript attempts to convert both operands to the same type for comparison. When you have a string and a number it attempts to convert the string to a number.""converts to0, giving you this result.Because of this behaviour many people chose to use the
===and!==operators instead. Their operands must be the same type to be considered equal.