JS Chapter 2 — Variables (let, const, var)

Chapter 2 — Variables (let, const, var)

MCQ 1

A food delivery app needs to store the customer's name.

Which is the best way?

A.

let customerName = "Rahul";

B.

customerName = "Rahul";

C.

"Rahul";

D.

let = "Rahul";

Answer: A


MCQ 2

A customer's cart total changes whenever items are added.

Which keyword is most appropriate?

A. const

B. let

C. var

D. None

Answer: B


MCQ 3

A company's GST number never changes while the page is running.

Which keyword is best?

A. let

B. var

C. const

D. change

Answer: C


MCQ 4

let city = "Delhi";
city = "Mumbai";
console.log(city);

What is printed?

A. Delhi

B. Mumbai

C. Error

D. Undefined

Answer: B


MCQ 5

const country = "India";
country = "USA";

Result?

A. USA

B. India

C. Error

D. Undefined

Answer: C


MCQ 6

A movie ticket counter keeps updating the number of available seats.

Which keyword should store the seat count?

A. const

B. let

C. fixed

D. final

Answer: B


MCQ 7

Which statement creates a variable correctly?

A.

let price = 500;

B.

let 500 = price;

C.

price let = 500;

D.

500 let price;

Answer: A


MCQ 8

let score = 90;
console.log(score);

Output?

A. score

B. 90

C. Error

D. Undefined

Answer: B


MCQ 9

A variable stores today's weather.

Tomorrow the weather changes.

Which keyword makes most sense?

A. const

B. let

C. fixed

D. lock

Answer: B


MCQ 10

const pi = 3.14159;
console.log(pi);

Output?

A. Error

B. 3.14159

C. pi

D. Undefined

Answer: B


MCQ 11

Which variable name is VALID?

A.

let userName;

B.

let user-name;

C.

let 1user;

D.

let let;

Answer: A


MCQ 12

Which variable name is INVALID?

A.

let customerAge;

B.

let _price;

C.

let $salary;

D.

let first-name;

Answer: D


MCQ 13

let amount = 100;
amount = amount + 50;
console.log(amount);

Output?

A. 100

B. 150

C. 50

D. Error

Answer: B


MCQ 14

A petrol pump stores today's fuel price.

Tomorrow the government changes it.

Which keyword?

A. const

B. let

C. never

D. static

Answer: B


MCQ 15

let name = "Amit";
let city = "Delhi";

How many variables exist?

A. 1

B. 2

C. 3

D. 0

Answer: B


MCQ 16

let age = 25;
let age = 30;

Result?

A. 30

B. 25

C. Error

D. Undefined

Answer: C


MCQ 17

let age = 25;
age = 30;

Result?

A. Error

B. 25

C. Variable now stores 30

D. Undefined

Answer: C


MCQ 18

const tax = 18;
console.log(tax + 2);

Output?

A. 182

B. 20

C. Error

D. Undefined

Answer: B


MCQ 19

A variable stores the current logged-in user's name.

The next user logs in without refreshing the page.

Which keyword?

A. const

B. let

C. static

D. fixed

Answer: B


MCQ 20

let a = 10;
let b = a;
b = 20;
console.log(a);

Output?

A. 10

B. 20

C. Error

D. Undefined

Answer: A


MCQ 21

let balance = 1000;
balance = balance - 200;
console.log(balance);

Output?

A. 1200

B. 800

C. 1000

D. Error

Answer: B


MCQ 22

Which naming style is the JavaScript convention?

A.

let customer_name;

B.

let CustomerName;

C.

let customerName;

D.

let CUSTOMERNAME;

Answer: C


MCQ 23

A shopping app stores the maximum number of items allowed in a cart (50), which never changes.

Which keyword?

A. let

B. const

C. var

D. dynamic

Answer: B


MCQ 24

let product = "Laptop";
console.log(product);

product = "Phone";

console.log(product);

Output?

A.

Laptop
Phone

B.

Phone
Laptop

C.

Laptop
Laptop

D. Error

Answer: A


MCQ 25

Which statement is the most accurate?

A. Use const by default. Use let only when the value needs to change. Avoid var in modern JavaScript.

B. Always use var.

C. Always use let.

D. const and let are identical.

Answer: A

No comments:

Post a Comment

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