Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why using NULL with logical operator throws error in JS

This is the code I am testing --

Works fine

document.write( 1 && undefined ); // prints undefined
document.write( 1 && 3 ); // prints 3 
document.write( 1 && true ); // prints  true

Throws error

document.write( 1 && NULL ); // throws Error 

why using NULL throws arror although its working even for undefined

although i tested typeof NULL and its giving undefined but still its not working.let me know about this. (New to OOP programming)

like image 218
Trialcoder Avatar asked May 20 '26 03:05

Trialcoder


1 Answers

NULL does not exist, try this

try {
    document.write( 1 &&  NULL  );
} catch ( e) {
    document.write( 1 &&  null  );
}
like image 58
rab Avatar answered May 22 '26 15:05

rab