Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
alexteg317yThere could actually be a purpose to this in JavaScript, even though it could be written more concisely.
Not having strict equals means falsy values like 0, "" or undefined will be turned into null.
Coffeescript turns the existential operator for something like:
foobar?
into
(foobar != null)
for this specific purpose of catching all falsy values. -
sandeepb3057yI sometimes write code like this mainly so I can add extra logic in the future. Saves time down the line.
-
//stuff here
unsigned int v;
// more stuff here
If (v <0){
//Do Something of Important(*)
}
//again stuff -
andys8837yThis makes total sense in JS. It will return both null and undefined as null, but pass valid values trough (especially relevant for falsy ones like "" and 0).
Related Rants
The worst Code I saw was
if (value != null ) {
return value;
} else {
return null;
}
undefined
wk58
logic gem