Twenty-four, JavaScript - conditional operator

  • The conditional operator, also known as the ternary operator

               conditional expression? expression1: expression2

                - Execution order

                    When the conditional operator is executed again, the conditional expression will be evaluated and judged

                        If the result is true, execute expression1

                        If the result is false, execute expression 2

 

 

    <script>
        /*
            条件运算符,也称三元运算符
                条件表达式 ? 表达式1 : 表达式2
                - 执行顺序
                    条件运算符再执行时,会对条件表达式进行求值判断
                        如果结果为true,则执行表达式1
                        如果结果为false,则执行表达式2
        */
        
        let a = 10
        let b = 20
        a > b ? alert(1) : alert(2)
        
    </script>

Guess you like

Origin blog.csdn.net/z972065491/article/details/128329566
Recommended