You can use the isnull
function from the underscore library in typescript by importing the library and the types. First, install the library:
23 chars2 lines
Then, install the type definitions:
41 chars2 lines
After the installation, import the library and the types:
index.ts176 chars8 lines
In the example above, we import the entire underscore library as _
, and then we import only the isNull
function. Then, we use the function to check if a variable str
is null.
Note that the isNull
function is just an alias for the === null
comparison operator. If you need to check for null and undefined values, you can use the isUndefined
function or the _.isUndefined
method from underscore.
index.ts190 chars8 lines
gistlibby LogSnag