JS Chapter 4 — Operators

Chapter 4 — Operators


MCQ 1 — Cashback Calculation

An e-commerce app gives ₹150 cashback.

let wallet = 850;
let cashback = 150;

console.log(wallet + cashback);

What is printed?

A. 700

B. 1000

C. 850150

D. Error

Answer: B


MCQ 2 — Inventory Update

A warehouse has 240 phones.

18 phones are sold.

let stock = 240;

console.log(stock - 18);

Output?

A. 222

B. 258

C. 24018

D. Error

Answer: A


MCQ 3 — Team Capacity

A startup hires 16 developers.

Each developer receives 2 monitors.

let developers = 16;

console.log(developers * 2);

Output?

A. 18

B. 32

C. 162

D. 8

Answer: B


MCQ 4 — Monthly Subscription

Netflix charges ₹799 every month.

The yearly cost is calculated.

let monthly = 799;

console.log(monthly * 12);

Output?

A. 9588

B. 9600

C. 9488

D. Error

Answer: A


MCQ 5 — Bill Splitting

Four friends order food worth ₹2200.

let bill = 2200;

console.log(bill / 4);

Each friend pays...

A. 500

B. 550

C. 600

D. 450

Answer: B


MCQ 6 — Remaining Chocolates

A teacher has 23 chocolates.

They are distributed equally among 5 children.

console.log(23 % 5);

Output?

A. 4

B. 3

C. 5

D. 23

Answer: B

% gives the remainder, not the quotient.


MCQ 7 — Detect Even or Odd

A gaming server awards a bonus every second level.

let level = 18;

console.log(level % 2);

Output?

A. 0

B. 1

C. 18

D. 2

Answer: A

Remainder 0 means the number is even.


MCQ 8 — String + Number

A customer support system creates ticket IDs.

let ticket = "TKT-";
let id = 205;

console.log(ticket + id);

Output?

A.

205TKT-

B.

TKT-205

C.

Error

D.

NaN

Answer: B


MCQ 9 — Discount Bug

A developer writes:

let price = "1500";

console.log(price - 200);

Output?

A. 1300

B. 1500200

C. Error

D. NaN

Answer: A


MCQ 10 — Coupon Bug

Later, another developer writes:

let price = "1500";

console.log(price + 200);

Output?

A. 1700

B. 1500200

C. Error

D. NaN

Answer: B

+ behaves differently when a string is involved.


MCQ 11 — Predict the Output

console.log(8 + 3 * 2);

Output?

A. 22

B. 16

C. 11

D. Error

Answer: B

Multiplication happens before addition.


MCQ 12 — Parentheses Matter

console.log((8 + 3) * 2);

Output?

A. 22

B. 16

C. 11

D. 19

Answer: A


MCQ 13 — Shipping Calculator

An online store calculates:

let items = 3;
let price = 450;

console.log(items * price + 100);

Output?

A. 1450

B. 1350

C. 1550

D. 1400

Answer: A


MCQ 14 — Score Update

A cricket game updates the score.

let score = 95;

score += 6;

console.log(score);

Output?

A. 95

B. 101

C. 89

D. Error

Answer: B

score += 6 means score = score + 6.


MCQ 15 — Wallet Balance

let balance = 1200;

balance -= 350;

console.log(balance);

Output?

A. 850

B. 1550

C. 1200

D. Error

Answer: A


MCQ 16 — Salary Increase

let salary = 50000;

salary *= 2;

console.log(salary);

Output?

A. 50000

B. 100000

C. 25000

D. Error

Answer: B


MCQ 17 — Pizza Party

A pizza has 8 slices.

3 friends eat 2 slices each.

let slices = 8;

slices -= 3 * 2;

console.log(slices);

Output?

A. 2

B. 6

C. 4

D. Error

Answer: A


MCQ 18 — Increment Operator

An app counts notifications.

let notifications = 12;

notifications++;

console.log(notifications);

Output?

A. 12

B. 13

C. 14

D. Error

Answer: B


MCQ 19 — Decrement Operator

A parking lot has 50 free spaces.

One car parks.

let spaces = 50;

spaces--;

console.log(spaces);

Output?

A. 50

B. 49

C. 48

D. Error

Answer: B


MCQ 20 — Post Increment Trap ⭐

A game developer writes:

let lives = 3;

console.log(lives++);
console.log(lives);

Output?

A.

3
4

B.

4
4

C.

3
3

D.

4
3

Answer: A

lives++ returns the current value first, then increases it.


MCQ 21 — Pre Increment

The developer changes the code.

let lives = 3;

console.log(++lives);
console.log(lives);

Output?

A.

3
4

B.

4
4

C.

3
3

D.

4
3

Answer: B

++lives increases first, then returns the value.


MCQ 22 — Which Operator?

A fintech app needs to calculate the remaining amount after EMI payments.

Which operator is most suitable?

A. +

B. -

C. %

D. *

Answer: B


MCQ 23 — Detect Every 5th Customer

A supermarket gives a gift to every 5th customer.

Which expression correctly detects this?

A.

customerNumber / 5

B.

customerNumber % 5 === 0

C.

customerNumber * 5

D.

customerNumber + 5

Answer: B


MCQ 24 — Reading Production Code ⭐

A payment service processes this:

let amount = 100;

amount += 50;
amount *= 2;
amount -= 80;

console.log(amount);

What is printed?

A. 220

B. 300

C. 200

D. 180

Answer: A

Step-by-step:

  • 100 + 50 = 150

  • 150 × 2 = 300

  • 300 − 80 = 220


MCQ 25 — Real Production Bug 🐞

An intern writes:

let quantity = "5";

let totalItems = quantity + 1;

console.log(totalItems);

Customers report that adding one item shows "51" instead of 6.

What is the root cause?

A. JavaScript cannot add numbers.

B. quantity is stored as a string, so + performs string concatenation.

C. console.log() is incorrect.

D. + only works with decimals.

Answer: B

⭐ This is one of the most common real-world JavaScript bugs.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.