Back to Course

Introduction to JavaScript

0% Complete
0/0 Steps
  1. JavaScript: Basics
    9Topics
    |
    10 Quizzes
  2. JavaScript: Variables
    9Topics
    |
    10 Quizzes
  3. JavaScript: Conditional Statements
    10Topics
    |
    11 Quizzes
  4. JavaScript: Functions
    10Topics
    |
    11 Quizzes
  5. JavaScript: Scope
    6Topics
    |
    7 Quizzes
  6. JavaScript: Arrays
    11Topics
    |
    12 Quizzes
  7. JavaScript: Loops
    8Topics
    |
    9 Quizzes
  8. JavaScript: High Order Functions
    3Topics
    |
    3 Quizzes
Lesson 3, Topic 2
In Progress

JavaScript: If Statement

Yasin Cakal 31 Oct 2021
Lesson Progress
0% Complete

We carry out tasks in our daily life on the basis of some conditions. If a person is feeling hungry he’ll eat, if he’s feeling sleepy he’ll sleep. If it’s raining outside wear a raincoat before leaving home.

We can also use an if statement in programming to perform a task based on a condition:

if (true) {
  console.log('CodeOfCode will print.'); 
}

//Output: CodeOfCode will print.

There is an if statement in the example above. The if statement is made up of the following parts:

  1. The if keyword is followed by a pair of parentheses () and a code block, or block statement, denoted by a pair of curly braces {}.
  2. A condition is provided inside the parentheses () that evaluates to true or false.
  3. The code inside the curly braces runs, or executes, if the condition evaluates to true.
  4. The block will not execute if the condition evaluates to false.

Let’s practice the concept through a quiz!

Responses

Leave a Reply

%d bloggers like this: