JavaScript Daily Challenge How? ANYONE? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

19th Aug 2017, 12:15 AM
¤ rookie ¤
¤ rookie ¤ - avatar
12 Answers
+ 18
null == undefined is true (1) null === undefined is false (0) So, 1 + 0 = 1 is alerted.
19th Aug 2017, 12:40 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 9
@krishna teja so you mean sir true = 1 and false = 0? is that it?
19th Aug 2017, 1:01 AM
¤ rookie ¤
¤ rookie ¤ - avatar
+ 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 😊
19th Aug 2017, 1:20 AM
¤ rookie ¤
¤ rookie ¤ - avatar
+ 7
@Ben Bright oh I see that's how it is. thank you 😊
19th Aug 2017, 11:54 PM
¤ rookie ¤
¤ rookie ¤ - avatar
+ 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
19th Aug 2017, 1:06 AM
Benneth Yankey
Benneth Yankey - avatar
+ 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?
19th Aug 2017, 3:14 PM
¤ rookie ¤
¤ rookie ¤ - avatar
+ 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
19th Aug 2017, 6:35 PM
Benneth Yankey
Benneth Yankey - avatar
19th Aug 2017, 2:25 AM
sayan chandra
sayan chandra - avatar
+ 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 .
19th Aug 2017, 2:39 PM
Kapil Whaval
Kapil Whaval - avatar
+ 2
I'm new here and don't know anything about it can someone teach me what the code is? pls
26th Aug 2017, 2:28 AM
Clement Opoku
Clement Opoku - avatar
0
х.
19th Aug 2017, 7:37 PM
opolvao
opolvao - avatar
0
х.
19th Aug 2017, 7:37 PM
opolvao
opolvao - avatar