JavaScript--条件演算子

2651 ワード


<html>
    <head>
        <meta charset="UTF-8">
        <title>title>
        <script type="text/javascript">
            /*
             *             
             *    :
             *           ?  1:  2;
             *  -      :
             *               ,            ,
             *               true,     1,       
             *               false,     2,       
             *                          ,
             *                        
             */

            //false?alert("  1"):alert("  2");

            var a = 300;
            var b = 143;
            var c = 50;

            //a > b ? alert("a "):alert("b ");

            //  a b     
            //var max = a > b ? a : b;
            //  a b c     
            //max = max > c ? max : c;

            //         ,     
            var max = a > b ? (a > c ? a :c) : (b > c ? b : c);

            //console.log("max = "+max);

            //"hello"?alert("  1"):alert("  2");


        script>
    head>
    <body>
    body>
html>