DEV Community

Discussion on: Differences between "null" and "undefined" keywords?

Collapse
 
emptyother profile image
emptyother

The new optional parameter for ES6 only cares about undefined.

function myFunc(a, b = 0) { console.log(a,b); }
myFunc(1); // 1 0
myFunc(1,null); // 1 null
myFunc(1,undefined); // 1 0
myFunc(1,getSomeNonExistingValue()); // 1 (null or 0)

Wouldn't it be simpler to use undefined instead of null everywhere? Just stop using null?

Collapse
 
alexparra profile image
Alex Parra

Yeah, this has tripped me a couple of times...