menu

JavaScript Basic Programs for Beginners

JavaScript Basic Programs for Beginners - Important Points


26. Which of the following is the correct way to convert a string to a number in JavaScript?

A. parseInt(string);

B. Number(string);

C. parseFloat(string);

D. All of the above

Discuss Work Space

Answer: option d

Explanation:

All of the options are correct ways to convert a string to a number in JavaScript.

27.

What is the output of the following code snippet?

console.log("hello".indexOf("l"));

A. 1

B. 2

C. 3

D. 4

Discuss Work Space

Answer: option b

Explanation:

The output of the code is "2" because the indexOf() method returns the index of the first occurrence of a substring in a string.

28. Which of the following is the correct way to round a number to the nearest integer in JavaScript?

A. Math.floor(number);

B. Math.round(number);

C. Math.ceil(number);

D. All of the above

Discuss Work Space

Answer: option b

Explanation:

The correct way to round a number to the nearest integer in JavaScript is by using the Math.round() method.

29.

What is the output of the following code snippet?

console.log("hello".slice(1, 3));

A. hel

B. el

C. llo

D. null

Discuss Work Space

Answer: option b

Explanation:

The output of the code is "el" because the slice() method returns a portion of a string between two indices.


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