JavaScript Multiple choices

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

How to write an IF statement in JavaScript?







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.

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


Next 5 multiple choice(s)


How do you call a function named "myFunction"?


How do you create a function in JavaScript?


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


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


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