How To Use Ternary Operator Using JavaScript?


Share:
Published By: Admin, Published On: Nov 19, 2021, Category: Javascript


Hello Friends,

Now let's see example of how to use ternary operator example.We will check how to use ternary operator. This is a short guide on use ternary operator in javascript. Here you will learn how to use javascript ternary operator. Let's get started with how to use ternary operator in javascript.

Here i will give you many example how to use ternary operator using javascript.

Example : 1
<!DOCTYPE html>  
<html>  
    <head>  
        <title>How To Use Ternary Operator Using JavaScript? - MyWebtuts.com</title>
    </head>  
    <body>
        <h3>How To Use Ternary Operator Using JavaScript? - MyWebtuts.com</h3>  
        <p> Welcome to the MyWebtuts.com </p> 
        <script>  
            let a = 354;  
            let val = ( a % 2 == 0) ? 'Even Number' : 'Odd Number';  
            alert(val);  
        </script>  
    </body>  
</html>   
Output :
Even Number
Welcome to the MyWebtuts.com
Example : 2
<!DOCTYPE html>  
<html>  
    <head>  
        <title>How To Use Ternary Operator Using JavaScript? - MyWebtuts.com</title>
    </head>  
    <body>
        <h3>How To Use Ternary Operator Using JavaScript? - MyWebtuts.com</h3>  
        <p> Welcome to the MyWebtuts.com </p> 
        <script>  
            let a = 899;  
            let a2 = ( a % 2 == 0) ? 'Even Number' : 'Odd Number';  
            alert(a2);  
        </script>  
    </body>  
</html>     
Output :
Odd Number
Welcome to the MyWebtuts.com

It will help you...

Share: