+ 2

Is "" as same as null in javascript?

I found this codes from a book. I can't understand why they use &&(and) because I don't know that second statement (name!="") is true or false? if (name!=null && name!=""){ alert("blah blah blah.."); } else{ alert("blah blah blah blah..."); }

28th Nov 2018, 6:34 AM
Isurujith Wijesundara
4 Respuestas
+ 2
null and "" are different. null means that the variable is not initialized yet. According to the above case it make sures that the name is initialized and it is not blank - some funny users like to remain their name blank😂.So that case would be very useful 😆
28th Nov 2018, 1:31 PM
Seniru
Seniru - avatar
+ 4
No, they are not the same. That condition is to make sure the variable 'name' is not null and also not empty string.
28th Nov 2018, 6:48 AM
Lord Krishna
Lord Krishna - avatar
+ 1
28th Nov 2018, 6:52 AM
Isurujith Wijesundara
+ 1
Seniru Pasan 👍👍
28th Nov 2018, 2:10 PM
Isurujith Wijesundara