menu

JavaScript Basic Programs for Beginners

JavaScript Basic Programs for Beginners - Important Points


21.

What is the output of the following code snippet?

console.log("hello".toUpperCase());

A. hello

B. HELLO

C. null

D. undefined

Discuss Work Space

Answer: option b

Explanation:

The output of the code is "HELLO" because the toUpperCase() method converts a string to uppercase.

22. Which of the following is the correct way to concatenate two strings in JavaScript?

A. string1.concat(string2);

B. string1 + string2;

C. string1.join(string2);

D. string1.append(string2);

Discuss Work Space

Answer: option b

Explanation:

The correct way to concatenate two strings in JavaScript is by using the "+" operator: "string1 + string2;".

23.

What is the output of the following code snippet?

console.log(2 + "3");

A. 23

B. 5

C. null

D. undefined

Discuss Work Space

Answer: option a

Explanation:

The output of the code is "23" because the number 2 is converted to a string when concatenated with the string "3".

24. Which of the following is the correct way to check if a variable is an array in JavaScript?

A. if (typeof myArray === "array") {}

B. if (myArray.isArray()) {}

C. if (myArray === "Array") {}

D. if (Array.isPrototypeOf(myArray)) {}

Discuss Work Space

Answer: option b

Explanation:

The correct way to check if a variable is an array in JavaScript is by using the isArray() method: "if (myArray.isArray()) {}".

25.

What is the output of the following code snippet?

console.log(Math.random() * 10);

A. a random number between 1 and 10

B. a random number between 0 and 10

C. 10

D. null

Discuss Work Space

Answer: option b

Explanation:

The output of the code is a random number between 0 and 10 because the Math.random() method generates a random number between 0 and 1.


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