Skip to content

Instantly share code, notes, and snippets.

@funfunction
Created July 6, 2020 18:09
Show Gist options
  • Save funfunction/0e64a5aa3abedfa237823d0bab2ef70b to your computer and use it in GitHub Desktop.
Save funfunction/0e64a5aa3abedfa237823d0bab2ef70b to your computer and use it in GitHub Desktop.
/**
@func
true if var is null or undefined
@param {*} v
@return {boolean}
*/
export const isNil = v => v === undefined || v === null;
//@tests
const aTrue = [undefined, null, (() => undefined)(), (() => null)(), (() => console.log())()];
const aFalse = ["", [], {}, () => undefined, "undefined", "null", NaN, -Infinity, 9e9999, 9999n];
logForeachParam(isNil)(aTrue);
logForeachParam(isNil)(aFalse);
// logForeachParam sourcecode at: https://gist.github.com/funfunction/42918a4751ae51828cfc4c2dd4c0678e
/**
@func complement
@param {*} v
@return {boolean}
*/
export const isNotNil = v => !isNil(v);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment