JavaScript study notes 20 - get the data type of the variable

//typeof 检测变量是什么类型的
//在控制台输出类型的名称
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie-edge">
    <title>Document</title>
    <script>
        var num = 10 ;
        console.log(typeof num);//number  数字型
        var str = 'pink' ;
        console.log(typeof str);//string  字符型
        var flag = true ;
        console.log(typeof flag);//boolean  布尔型
        var vari = undefined ;
        console.log(typeof vari);//undefined  
        var timer = null ;
        console.log(typeof timer);//object
        //prompt  去过来的值是字符型的   string   也就是不能进行一些运算
        var age = prompt('请输入您的年龄');
        console.log(typeof age);//这里从prompt里面取出来的值是字符类型的 string
    </script>
</head>

<body>

</body>

</html>

Please add a picture description

Please add a picture description

Learn from station b [JavaScript basic grammar-dom-bom-js-es6 new grammar-jQuery-data visualization echarts black horse pink teacher front-end basic video tutorial (more than 500 episodes) continued-Bilibili] https://b23. tv/YGIdOrv

Guess you like

Origin blog.csdn.net/m0_74282485/article/details/128418445