What is an if statement:-. Genius student



  • This will check a condition and if it is true execute the following code.
  • If you have single line code then no need of curly braces {}.
Syntax
if(condition) {
    //block of code to be executed if the condition  is true. 
}

Condition
Condition are checked by the following operators ==,>,<,<=,>=,!=
Example
3>4 => false
10<8 => false
3==3 => true
4!=4 => false
3<=4 => true


Code:-


<!DOCTYPE html>
<html>

<head>
 <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

 <h1>if</h1>

 <input type="button" onclick="chek();" value="check if">

 <script>
  function chek()
  {
   if (5 > 3) //This condition is true so if part execute
   {
    alert("This is alert box");
   }

  }
 </script>

</body>

</html>
What is an if statement:-. Genius student What is an if statement:-. Genius student Reviewed by Network security on October 14, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.