第一种方法typeof
typeof是一种运算符,它的值有以下几种
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>ces</title> </head> <body> <script> console.log(typeof "Liesbeth");//"string" console.log(typeof 12);//"number" console.log(typeof true); //"boolean" console.log(typeof undefined);//"undefined" console.log(typeof null);//"object" console.log(typeof {name:"Liesbeth"});//"object" console.log(typeof function(){});//"function" console.log(typeof []);//"object" console.log(typeof new Date);//"object" console.log(typeof /[0-9]/);//'object' console.log(typeof new Number(123));//'object' function Person(){}; console.log(typeof new Person);//'object' </script> </body> </html>