JavaScript String and literals Quiz

Topics : JavaScript Strings and literals

JavaScript Quiz #03 - JavaScript String

5 mins read

1. What is the output?

 let str = "Hello";
console.log(str.split(""));

2. What is the output of the following code snippet?

 let x = “John”;
let y = new String(“John”);
console.log(x === y);

3. What is the output of the following code snippet?

 let str =5+ 2;
console.log(str);

4. What is the output of the following code snippet?

 let str = “Hello” — 2;
console.log(str);

5. Which method is used to remove whitespace from both ends of a string?

6. What is the output of the following code snippet?

 let str = “Hello, World!;
console.log(str.slice(0, 5))

7. What is the output of the following code snippet?

 const str = null;
str.toString();

8. What is the output of the following code snippet?

 let str = “Hello, World!;
console.log(str.substr(-3))

9. Which code snippet checks if a string is empty in JavaScript?

10. What is the difference between using single quotes (') and double quotes (") to create a string literal in JavaScript?

11. Which of the following is an example of a multiline string literal?