Underscore.js _.isUndefined() Function (original) (raw)

Last Updated : 01 Aug, 2023

_.isUndefined() function:

Syntax:

_.isUndefined(value)

Parameters:
It takes only one argument which is the value or the variable that needs to be checked.

Return value:
It returns true if the value or parameter passed is undefined or else it returns false.

Examples:

  1. Passing a variable to the _.isUndefined() function:
    The _.isUndefined() function takes the parameter passed to it. So, here it will check the variable ‘a’ which is passed. Since the value of ‘a’ is defined earlier as 10, so, it is a defined variable. Hence, the output will be false.
    Output:
  2. Passing a number to the _.isUndefined() function:
    If we pass a number to the _.isUndefined() function then it checks whether that number is undefined or not. Since, we know all numbers are defined already. Therefore, the answer will be false.
    Output:
  3. Passing “undefined” to _.isUndefined() function:
    The _.isUndefined() function takes the element passed to it which is “undefined” here. Since the parameter passed is undefined, therefore the output will be true.
    Output:
  4. Passing missingVariable to the _.isUndefined() function:
    Here we are passing ‘window.missingVariable’ as a parameter. But here we have not defined any variable. So the missingVariable has no value. And hence, it is undefined. The output is true.
    Output:

NOTE: These commands will not work in Google console or in firefox as for these additional files need to be added which they didn’t have added.
So, add the given links to your HTML file and then run them.
The links are as follows:

Similar Reads