SoFunction
Updated on 2025-03-01

Use the typeof method to determine the undefined type

Regarding js to determine the undefined type, use the typeof method. Typeof returns a string, one of which is undefined.

js judge undefined type

if (reValue== undefined)
{
alert("undefined");
}

I found that I couldn't judge it, so I finally checked the information and used the typeof method:

if (typeof(reValue) == "undefined")
{ 
alert("undefined");
}

typeof returns a string, and there are six possibilities: "number", "string", "boolean", "object", "function", and "undefined".
Be sure to pay attention when using it.