JavaScript Multiple choices


Total available count: 50
Subject - JavaScript Frameworks
Subsubject - JavaScript

How to write an IF statement in JavaScript?


 

 

 

 



A


Solution:-

JavaScript - if...else Statement:

While writing a program, there may be a situation when you require to adopt one out of a given set of paths. In such cases, you require to use conditional statements that permit or allow your program to make correct decisions and perform the right actions.

JavaScript supports conditional statements which are used to perform different actions based on different conditions. Here we will explain the if statement.

The statement if is the fundamental control statement that allows or permits JavaScript to make decisions and execute statements conditionally.

if (expression) {
 Statement(s) to be executed the expression if is true
}

Here a JavaScript expression is evaluated. If the resulting value is true, the given statement(s) are executed. If the expression is false, then no statement would be not executed. Most of the time, you will use comparison operators while making decisions.

Try and understand how the if statement works from the following example.

<html>
   <body> 
      <script type = "text/javascript">
         <!--
            var age = 25;
         
            if( age > 2 ) {
               document.write("<b>Qualifies for driving</b>");
            }
         //-->
      </script>
   </body>
</html>

 




Next 5 multiple choice(s)

1

How do you call a function named "myFunction"?

2

How do you create a function in JavaScript?

3

How do you write "Hello World" in an alert box?

4

What is the correct syntax for referring to an external script called "xxx.js"?

5

Is The external JavaScript file must contain the <script> tag?

Comments