+ 8
JavaScript Daily Challenge How? ANYONE?
//How is the output is 1? var a = null == undefined; var b = null === undefined; var c = a + b; alert(c) //null is nothing right?
12 Respuestas
+ 18
null == undefined is true (1)
null === undefined is false (0)
So, 1 + 0 = 1 is alerted.
+ 9
@krishna teja so you mean sir true = 1 and false = 0? is that it?
+ 8
Thanks guys 🙌 it is clear now 😊 I was just confused where the 1 came from. But it now clear to me thanks to you guys 😊
+ 7
@Ben Bright oh I see that's how it is. thank you 😊
+ 6
As Sir Krishna already laid out just want to make it more clearer:
== // checks for same value of its operands
=== // checks for same type and value of its operands
in terms of ==
null and undefined have same value // nothing
so null == undefined // true
in terms of ===
typeof null // object
typeof undefined // undefined
so null === undefined // false
Hence, true + false => 1 + 0 => 1
+ 6
@kapil whaval oh i see that's the thing that really confused me thank you. How about null? does it also return to 1 or 0?
+ 5
@rookie I guess what you want to know is how some types are converted to boolean. Here is a little Boolean Conversion cheatsheet for you:
empty string '', null, undefined and NaN
- All the above converts to false
- Any other type apart from those above converts to true
+ 2
Yes, if any condition is true then 1 is returned and if condition is false then 0 is returned ... for e.g if we write c = 5>2 .. here 5 is greater than 2 thus it will become c = 1 .. Hence, 1 will be assigned to c .
+ 2
I'm new here and don't know anything about it can someone teach me what the code is? pls
0
х.
0
х.