What is the main purpose of operators in programming?
Operators help us perform actions on values or variables, like adding numbers or comparing values.
Click to reveal answer
beginner
Give an example of a simple operator in JavaScript.
The + operator adds two numbers, like 2 + 3 equals 5.
Click to reveal answer
beginner
Why can't we just write values without operators?
Without operators, the computer wouldn't know how to combine or compare values to get results.
Click to reveal answer
beginner
What types of operations do operators allow us to do?
Operators let us do math (like +, -, *), compare values (like ==, >), and combine logic (like &&, ||).
Click to reveal answer
beginner
How do operators make programming easier?
They let us write short, clear instructions to do tasks instead of explaining every small step.
Click to reveal answer
What does the + operator do in JavaScript?
ASubtracts two numbers
BChecks if two values are equal
CAdds two numbers or joins strings
DDivides two numbers
✗ Incorrect
The + operator adds numbers or joins (concatenates) strings.
Why do we need operators in programming?
ATo display text on the screen
BTo store data permanently
CTo create new variables automatically
DTo perform actions like math or comparisons on values
✗ Incorrect
Operators let us perform actions such as math and comparisons.
Which operator checks if two values are equal in JavaScript?
A==
B+
C*
D&&
✗ Incorrect
The == operator compares two values for equality.
What kind of operation does the && operator perform?
AAddition
BLogical AND
CMultiplication
DSubtraction
✗ Incorrect
The && operator performs a logical AND operation.
If you want to combine two strings, which operator would you use?
A+
B-
C*
D/
✗ Incorrect
The + operator joins two strings together.
Explain why operators are important in programming using a real-life example.
Think about how you use math or comparisons in daily life.
You got /3 concepts.
List three types of operations that operators allow you to do in JavaScript.
Consider adding numbers, checking if values are equal, and combining true/false conditions.
You got /3 concepts.
Practice
(1/5)
1.
Why do we need operators in JavaScript?
Choose the best reason.
easy
A. To perform calculations and compare values
B. To create new variables automatically
C. To write comments in the code
D. To change the color of the webpage
Solution
Step 1: Understand the role of operators
Operators are symbols that let us do math like adding or compare values like checking if one number is bigger than another.
Step 2: Eliminate unrelated options
Creating variables, writing comments, or changing colors are not done by operators but by other parts of JavaScript or CSS.
Final Answer:
To perform calculations and compare values -> Option A
Quick Check:
Operators = calculations and comparisons [OK]
Hint: Operators do math and comparisons in code [OK]
Common Mistakes:
Thinking operators create variables
Confusing operators with comments
Believing operators change webpage style
2.
Which of these is the correct way to add two numbers a and b in JavaScript?
easy
A. a plus b
B. a + b
C. a & b
D. a - b
Solution
Step 1: Identify the addition operator
In JavaScript, the plus sign + is used to add two numbers.
Step 2: Check each option
a plus b uses words which is invalid syntax. a & b uses & which is a bitwise AND operator, not addition. a - b uses minus - which subtracts.
Final Answer:
a + b -> Option B
Quick Check:
Addition operator = + [OK]
Hint: Use + sign to add numbers in JavaScript [OK]
Common Mistakes:
Writing words instead of symbols
Using & instead of +
Confusing subtraction with addition
3.
What will be the output of this code?
let x = 5;
let y = 10;
console.log(x > y);
medium
A. true
B. 5
C. false
D. 10
Solution
Step 1: Understand the comparison operator
The operator > checks if the left value is greater than the right value.
Step 2: Compare the values of x and y
Since x = 5 and y = 10, 5 is not greater than 10, so the expression x > y is false.
Final Answer:
false -> Option C
Quick Check:
5 > 10 = false [OK]
Hint: Compare values carefully with > or < [OK]
Common Mistakes:
Assuming 5 is greater than 10
Confusing output with variable values
Mixing up true and false
4.
Find the error in this code snippet:
let a = 7;
let b = 3;
let result = a * b;
console.log(result);
Why is the output not showing the product?
medium
A. The multiplication operator is wrong
B. Variables a and b are not declared
C. Missing semicolon after console.log
D. No error, code works fine
Solution
Step 1: Check operator and variables
The operator * correctly multiplies a and b. Both variables are declared with let.
Step 2: Verify syntax and output
Semicolons are optional in JavaScript and the code will output 21 correctly.
Final Answer:
No error, code works fine -> Option D
Quick Check:
Multiplication with * works fine [OK]
Hint: Check if operator and variables are declared properly [OK]
Common Mistakes:
Thinking semicolon is mandatory
Confusing * with another operator
Assuming variables are undeclared
5.
You want to check if a number n is between 10 and 20 (inclusive). Which operator expression correctly does this?
hard
A. n >= 10 && n <= 20
B. n > 10 || n < 20
C. n > 10 && n < 20
D. n == 10 && n == 20
Solution
Step 1: Understand inclusive range check
To include 10 and 20, use >= for 10 and <= for 20.
Step 2: Analyze each option
n > 10 && n < 20 excludes 10 and 20 because it uses > and <. n > 10 || n < 20 uses OR which allows values outside the range. n == 10 && n == 20 checks if n equals both 10 and 20 simultaneously, which is impossible.
Final Answer:
n >= 10 && n <= 20 -> Option A
Quick Check:
Inclusive range uses >= and <= with AND [OK]
Hint: Use >= and <= with && for inclusive range checks [OK]
Common Mistakes:
Using > and < excludes boundary values
Using || instead of && allows wrong values
Checking equality to two values at once
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.