(1) Highlights of javascript in Silicon Valley (1) [Variables] [Relationship (comparison) operations] [Logical operations]

The basics in html basics, quote basic operations, do not need to repeat them.  

1. Variable

 

2. Relation (comparison) operations

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">

        var a = "12";
        var b = 12;

        alert( a == b ); // true
        alert( a === b ); // false

    </script>
</head>
<body>

</body>
</html>

3. Logic operations

Pay attention to short-circuit operation: when the && or || operation has a result. The following expressions are no longer executed.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
   /*     在JavaScript语言中,所有的变量,都可以做为一个boolean类型的变量去使用。
        0 、null、 undefined、””(空串) 都认为是 false;*/

        // var a = 0;
        // if (a) {
        //     alert("零为真");
        // } else {
        //     alert("零为假");
        // }

        // var b = null;
        // if (b) {
        //     alert("null为真");
        // } else {
        //     alert("null为假");
        // }

        // var c = undefined;
        // if (c) {
        //     alert("undefined为真");
        // } else {
        //     alert("undefined为假");
        // }

        // var d = "";
        // if (d) {
        //     alert("空串为真");
        // } else {
        //     alert("空串为假");
        // }


/*         && 且运算。
		有两种情况:
		第一种:当表达式全为真的时候。返回最后一个表达式的值。
		第二种:当表达式中,有一个为假的时候。返回第一个为假的表达式的值*/

        var a = "abc";
        var b = true;
        var d = false;
        var c = null;

        // alert( a && b );//true
        // alert( b && a );//true
        // alert( a && d ); // false
        // alert( a && c ); // null

 /*      || 或运算
       第一种情况:当表达式全为假时,返回最后一个表达式的值
       第二种情况:只要有一个表达式为真。就会把回第一个为真的表达式的值*/
        // alert( d || c ); // null
        // alert( c|| d ); //false

        // alert( a || c ); //abc
        // alert( b || c ); //true

    </script>
</head>
<body>

</body>
</html>

 

Link: B station is still Silicon Valley javaweb

Guess you like

Origin blog.csdn.net/qq_41048982/article/details/108970267