To determine whether the input is null get the JS code for the input type

  • 2020-03-26 21:40:47
  • OfStack

Use the typeof algorithm

Typeof has an undefined operand and returns "undefined".

Here, x is defined as the operand:

There are five cases;

Typeof (x) returns "number";

Typeof (x) returns "string";

Typeof (x) returns a Boolean;

Object, array, null&sponge; When: typeof(x) returns "object";

The function typeof(x) returns "function".

Such as:


<script type="text/javascript">
    var x=123456;
    alert( typeof(x));//The pop-up "number".
</script>


Related articles: