MCQ Single Best Answer Difficult

QWhat is the result of the following code in JavaScript?
const str = 'Hello, world!';
console.log(str.slice(0, 5));

ID: #4920 Javascript String MCQ 181 views
Question Info
#4920Q ID
DifficultDifficulty
Javascript String MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A Hello
  • B world
  • C Hello,
  • D world!
Correct Answer: Option A

Explanation

The slice() method returns the characters in a string between two specified indices.
In this case, the indices are 0 and 5, so the method returns the characters from the beginning of the string up to but not including the character at index 5, which is 'Hello'.

Share This Question

Challenge a friend or share with your study group.