<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
/* typeof运算符的返回结果是一个字符串,可以使用比较运算符“==”来判断
typeof返回的检测结果是否符合预期
*/
var a='12';
console.log(typeof a=='string');
console.log(typeof a=='number');
</script>
</body>
</html>
数据类型检测
最新推荐文章于 2025-12-11 21:57:31 发布
本文通过一个简单的示例介绍了如何使用JavaScript的typeof运算符进行变量类型的检测,并演示了如何判断一个变量是否为字符串。
1949

被折叠的 条评论
为什么被折叠?



