Master JavaScript Programming From Scratch

Clear, interactive, and structured JavaScript lessons designed for absolute beginners.

Operators & Control Flow

Learn how JavaScript uses operators to calculate, compare, and combine values, and how control flow helps a program make decisions.

What are Operators?

Operators are symbols used to perform operations on values. For example, + adds numbers and > compares values.

Operators are used throughout JavaScript programs for calculations, comparisons, assignments, and logical decisions.

JavaScript programming and operators

JavaScript programming uses operators to work with values and expressions.

Common Types of Operators

Arithmetic Operators

Used for mathematical calculations.

+   -   *   /   %   **
Comparison Operators

Compare values and produce true or false.

===   !==   >   <   >=   <=
Logical Operators

Combine or evaluate logical conditions.

&&   ||   !
Assignment Operators

Assign or update values stored in variables.

=   +=   -=   *=

How an Operator Works

Operand → Operator → Result
Value 1
+
Value 2
=
Result

Example 1: Arithmetic Operators

Arithmetic operators are used to perform basic mathematical calculations.

const students = 25;
const newStudents = 15;

const totalStudents = students + newStudents;
const remaining = totalStudents - 5;

console.log("Total Students:", totalStudents);
console.log("After 5 Students Leave:", remaining);
console.log("CIIT Training Institute - JavaScript");

Output

Total Students: 40
After 5 Students Leave: 35
CIIT Training Institute - JavaScript

Comparison and Logical Operators

Comparison operators check values and return true or false. Logical operators can combine multiple conditions.

Example 2: Comparison and Logical Operators

In this example, we check whether a student's marks meet the required condition.

const marks = 82;
const attendance = 90;

const marksPassed = marks >= 40;
const attendancePassed = attendance >= 75;

const eligible = marksPassed && attendancePassed;

console.log("Marks Passed:", marksPassed);
console.log("Attendance Passed:", attendancePassed);
console.log("Eligible:", eligible);
console.log("Student: Neha");

Output

Marks Passed: true
Attendance Passed: true
Eligible: true
Student: Neha

What is Control Flow?

Control flow means controlling the order in which statements are executed in a program.

JavaScript provides statements such as if...else, switch, and loops to control program execution.

Simple Idea

Operators help us create conditions, and control flow decides what the program should do based on those conditions.

Operators + Conditions + Control Flow
Values
→
Operators
→
Condition
→
Program Action

What You Will Learn in This Module

Module Topics

• Arithmetic Operators

• Comparison & Logical Operators

• If Else

• Switch

• Loops

Summary

Operators are used to calculate, compare, assign, and combine values in JavaScript. Control flow statements use conditions to control how a program executes. In the next lessons, you will learn each operator and control-flow concept step by step.