1、JS的两种引用方式

如下所示:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试一</title>
    <!-- 下面这个标签可以出现在任何位置!! -->
    <script>
        alert("这是内部脚本!");
    </script>
    <!-- 外部脚本 -->
    <script src="./js/demo1.js"></script>
    
</head>
<body>
    
</body>
</html>
2、JS的输出语句

测试代码如下所示:

<!-- js的输出语句 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试JS输出语句</title>
    <script>
        // 浏览器弹出警告框
        alert("Hello World!");
        // 写入HTML,在浏览器中展示
        document.write("Hello World!");    //可以写入标签
        // 写入浏览器控制台
        console.log("Hello World!");
    </script>
</head>
<body>
    
</body>
</html>
3、JS中的数据类型转换
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //数字字符串转换为数字
        alert(parseInt("123"));     //输出123
        //带字符的数字转换为数字    
        alert(parseInt("123a111")); //输出123
        //开头就是字母的字符串转数字
        alert(parseInt("a111222"));  //输出NaN
    </script>
</head>
<body>
    
</body>
</html>

其他类型转为boolean: Number:0和NaN为false,其他均转为true。 String:空字符串为false,其他均转为true。 Null和undefined:均转为false。