Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a word that covers both Null and Undefined?

I sometimes have to write code in JavaScript that handles both null and undefined the same way. For example, a function that removes from an array every item that is either null or undefined. How should I name the function?

removeNullAndUndefined is very long. removeNull is short but imprecise. Ideally I want to name it removeX, where X has the meaning "null or undefined".

Does anyone know a good word for X?

like image 772
gabor Avatar asked Aug 01 '19 15:08

gabor


People also ask

Are null and undefined interchangeable?

undefined and null variables oftentimes go hand-in-hand, and some use the terms interchangeably. Though, there is a difference between them: undefined is a variable that refers to something that doesn't exist, and the variable isn't defined to be anything. null is a variable that is defined but is missing a value.

Is null == undefined?

It means null is equal to undefined but not identical. When we define a variable to undefined then we are trying to convey that the variable does not exist . When we define a variable to null then we are trying to convey that the variable is empty.

Why is null == undefined true?

Both undefined and null are falsy by default. So == returns true. But when we use the strict equality operator (===) which checks both type and value, since undefined and null are of different types (from the typeof Operator section), the strict equality operator returns false.

What is the relationship between null and undefined?

In JavaScript, undefined is a type, whereas null an object. It means a variable declared, but no value has been assigned a value. Whereas, null in JavaScript is an assignment value. You can assign it to a variable.


1 Answers

Yes: Nullish. For instance, in the current Stage 3 Nullish Coalescing Operator proposal.

So: removeNullish or similar.

like image 95
T.J. Crowder Avatar answered Sep 29 '22 07:09

T.J. Crowder