The typeof operator

You can use the typeof operator to detect the data typeof a variable.

null

Null in JavaScript means “nothing”.

Null is a special type with a single value. Represents an empty object reference.

undefined

In JavaScript, undefined is a variable with no set value.

Typeof a variable with no value returns undefined.

 

The typeof operator to detect the data typeof a variable

typeof "John"                / / return a string
typeof 3.14                  / / return number
typeof false                 / / returns a Boolean
typeof [1.2.3.4]             / / return the object
typeof {name:'John'.age:34} / / return the object
Copy the code

The code is as follows:

<! DOCTYPEhtml>
<html>
	<head>
		<meta charset="utf-8">
		<title>Typeof, null, and undefined</title>
	</head>
	<body>
		<p>The typeof operator returns the typeof a variable or expression</p>
		<! -- <p>null is an object </p>
		<p
Copy the code