Strict mode-var:- genius student


  • The strict mode will make more changes to normal javaScript semantic.
  • It is not a statement, but a literal expression.
  • The use strict is used to indicate that the code should be executed in "strict mode".
  • Strict mode can be declared by adding "use strict"; to the beginning of a script or a function
  • For the global scope we can declare at the beginning of a script, (all code in the script will execute in strict mode).
Code:-

  • <!DOCTYPE html> 
  • <html> 
  •  
  • <head> 
  •  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  • </head> 
  •  
  • <body> 
  •  
  •  <h1>"strict" Should declare the variable using var keyword</h1> 
  •  
  •  
  •  <input type="button" onclick="fun_strict();" value="strict function"> 
  •  <script> 
  •   function fun_strict() 
  •   { 
  •    "use strict"; 
  •    try 
  •    { 
  •     a = 90; 
  •    } 
  •    catch (err) 
  •    { 
  •     alert("Error is : " + err.message); 
  •    } 
  •   } 
  •  </script> 
  •  
  • </body> 
  •  
  • </html>
Strict mode-var:- genius student Strict mode-var:- genius student Reviewed by Network security on November 04, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.