源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>typeof运算符返回变量或表达式的类型.</p> <button onclick="myFunction()">试试</button> <p id="demo"></p> <script> function myFunction() { var y = "John"; var x = + y; document.getElementById("demo").innerHTML = typeof x + "<br>" + x; } </script> </body> </html>
运行结果