Short circuting with:- JavaScript




In this example two function are used and both are return same values, but we recommended to use the second one.

Code:-


  • <!DOCTYPE html> 

    • <html> 
    •  
    • <head> 
    •  <meta name="viewport" content="width=device-width, initial-scale=1"> 
    •  
    •  <script> 
    •   /* 
    •       Both function are same functionality, But we are recommended the second function 
    •       */ 
    •   function wrng_way(title) 
    •   { 
    •    if (!title) 
    •    { 
    •     title = "Untitled Document"; 
    •    } 
    •    alert(title); 
    •   } 
    •  
    •   function corct_way(title) 
    •   { 
    •    title = title || "Untitled Document"; 
    •    alert(title); 
    •   } 
    •  </script> 
    •  
    • </head> 
    •  
    • <body> 
    •  <button onclick="corct_way();">Call Correct way</button> 
    •  <button onclick="wrng_way();">Call Wrong Way</button> 
    •  
    • </body> 
    •  
    • </html>
    Short circuting with:- JavaScript Short circuting   with:- JavaScript Reviewed by Network security on November 11, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.