JS Coding Questions Logo
JS Coding Questions
#148💼 Interview💻 Code

What are the recommendations to create new object

Advertisement

728x90

It is recommended to avoid creating new objects using new Object(). Instead you can initialize values based on it's type to create the objects.

1. Assign {} instead of new Object()

2. Assign "" instead of new String()

3. Assign 0 instead of new Number()

4. Assign false instead of new Boolean()

5. Assign [] instead of new Array()

6. Assign /()/ instead of new RegExp()

7. Assign function (){} instead of new Function()

You can define them as an example,

javascript
1var v1 = {};
2
3var v2 = "";
4
5var v3 = 0;
6
7var v4 = false;
8
9var v5 = [];
10
11var v6 = /()/;
12
13var v7 = function () {};

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 63

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
148of476