+ 8

I don't understand the result

Why the result is 0? 1 is a number and "1" is a string, or am I wrong? If (1 != "1") {document.write(1);} Else {document.write(0);}

27th Mar 2019, 4:43 PM
Leonardo
Leonardo - avatar
5 Respuestas
+ 20
== is used to check two thing are equal in value but not in type so 1 == "1" will be true and 1 != "1" will be false
27th Mar 2019, 5:07 PM
VEDANG
VEDANG - avatar
+ 5
It will print 0 bcoz 1!="1" false
29th Mar 2019, 8:15 AM
Rajesh Rathore
Rajesh Rathore - avatar
+ 3
Coder I selected the best answer: isn't it enough?
29th Mar 2019, 12:56 PM
Leonardo
Leonardo - avatar
+ 2
If you use === operator it would print 1. This compares only the value and not the type. This ia because there are no data types in javascript and to print 1 in this case only the === operator was added to js and not to java. Also this is only present in strongly typed languages i.e. those that have no type specification.
28th Mar 2019, 3:33 PM
Anshumaan Mishra