menu

JavaScript Basic Programs for Beginners

JavaScript Basic Programs for Beginners - Important Points


11. Which of the following is the correct way to create an array in JavaScript?

A. var myArray = ();

B. var myArray = [];

C. myArray = array();

D. myArray = {};

Discuss Work Space

Answer: option b

Explanation:

The correct way to create an array in JavaScript is by using the syntax "var myArray = [];".

12.

What is the output of the following code snippet?

console.log(3 === "3");

A. 1

B. 0

C. null

D. undefined

Discuss Work Space

Answer: option b

Explanation:

The output of the code is "false" because 3 is a number and "3" is a string, so they are not equal when using the strict equality operator (===).

13. Which of the following is the correct way to access an element in an array in JavaScript?

A. myArray[elementIndex]

B. elementIndex.myArray

C. myArray[elementValue]

D. myArray[elementIndex][elementValue]

Discuss Work Space

Answer: option a

Explanation:

The correct way to access an element in an array in JavaScript is by using the syntax "myArray[elementIndex]".

14.

What is the output of the following code snippet?

console.log(5 > 2 && 2 < 4);

A. 1

B. 0

C. null

D. undefined

Discuss Work Space

Answer: option a

Explanation:

The output of the code is "true" because both conditions are true when using the logical AND operator (&&).

15. Which of the following is the correct way to write a for loop in JavaScript?

A. for (var i = 0; i < array.length; i++) {}

B. for (i = 0; i < array.length; i++) {}

C. for (var i = 0; i < array.length; i--) {}

D. for (i = 0; i < array.length; i = i + 2) {}

Discuss Work Space

Answer: option a

Explanation:

The correct way to write a for loop in JavaScript is by using the syntax "for (var i = 0; i < array.length; i++) {}".


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