menu

JavaScript Basics

JavaScript Basics - Important Points


1.

Which of the following is not a valid way to declare a variable in JavaScript?

A. var myVar = 5;

B. let myVar = 10;

C. const myVar = "hello";

D. myVar = true;

Discuss Work Space

Answer: option d

Explanation:

D is not a valid way to declare a variable in JavaScript. You must use a declaration keyword such as var, let, or const.


2. What does the typeof operator return for null in JavaScript?

A. null

B. undefined

C. object

D. number

Discuss Work Space

Answer: option c

Explanation:

The typeof operator in JavaScript returns "object" for null because null is considered to be an empty object reference.

3. What is the difference between let and var in JavaScript?

A. There is no difference between let and var.

B. let is block-scoped, while var is function-scoped.

C. var is block-scoped, while let is function-scoped.

D. let can only be used to declare global variables.

Discuss Work Space

Answer: option b

Explanation:

let is block-scoped, meaning it is only accessible within the block it is declared in, while var is function-scoped, meaning it is accessible within the function it is declared in.

4. Which of the following is not a way to loop through an array in JavaScript?

A. for loop

B. while loop

C. do-while loop

D. if statement

Discuss Work Space

Answer: option d

Explanation:

An if statement is not a way to loop through an array in JavaScript. It is a conditional statement used to test a condition and execute code if the condition is true.

5. What does NaN stand for in JavaScript?

A. Not a Name

B. Not a Number

C. Not a Null

D. Not a Boolean

Discuss Work Space

Answer: option b

Explanation:

NaN stands for "Not a Number" in JavaScript. It is a value returned when a mathematical operation does not result in a valid number.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now