Use Ternary operator to make multiple operations - Javascript Operator

Javascript examples for Operator:Ternary Operator

Description

Use Ternary operator to make multiple operations

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*w  w  w  .  j av a 2  s.c o  m*/
var flag = true;
(flag) ? (
        flag = 'a',      //first operation
        letterflag = 'a' //second operation
) : (
        flag = 'b',
        letterflag = 'b'
);
console.log(flag);
console.log(letterflag);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials