JavaScript MCQ Javascript Data Types MCQ Question #4880
Single Choice Easy

QWhich of the following is not a valid way to create a new string in JavaScript?

ID: #4880 Javascript Data Types MCQ 167 views
Question Info
#4880Q ID
EasyDifficulty
Javascript Data Types MCQTopic

Choose the Best Option

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

  • A var str = new String("Hello World!");
  • B var str = String("Hello World!");
  • C var str = "Hello World!";
  • D var str = 'Hello World!';
Correct Answer

Explanation

While A, D, and E are all valid ways to create a new string in JavaScript,
using the "new" keyword and the String constructor function (as in C) is not recommended,
because it can cause confusion with the primitive string data type.
It is better to use either of the other options.

Share This Question

Challenge a friend or share with your study group.