self_example/java_web/JavaScript/html/06-运算符.html

72 lines
1.5 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>06-运算符</title>
</head>
<body>
<script>
/**
* ==:
* 1.判断类型是否一样,如果不一样,则进行类型转换
* 2.再去比较其值
*
* ===:全等于
* 1.判断类型是否一样,如果不一样,则直接返回false
* 2.如果一样再去比较其值
*/
// var age1 = 20;
// var age2 = "20";
//
// // alert(age1==age2); //true
// alert(age1 === age2); //false
/**
* 类型转换:
* *其他类型转为number:
* 1.string: 按照字符串的字面值转为数字。如果字面值不是数字则转为NAN.一般使用parseInt进行转换
* 2.boolean:true转为1false转为0
*
*
* *其他类型转为boolean: --一般以后用于健壮性的判断
* 1.number:0和NaN转为false,其他数字转为true
* 2.string:空字符串转为false,其他字符串转为true
* 3.null:转为false
* 4.undefined:转为false
*
*
*
*/
// var str = +"abc";
// var str = +"20";
// var str="20";
// alert(parseInt(str) + 1);
// var flag = +true
// alert(flag)
// var flag = 0;
// var flag = 3;
//var flag = "1";
// var flag=null;
var flag=undefined;
if(flag){
alert("转为true");
}else {
alert("转为false");
}
</script>
</body>
</html>