DEV Community

Cover image for JS Test #2: How to create an array in JavaScript
Coderslang: Become a Software Engineer
Coderslang: Become a Software Engineer

Posted on • Edited on • Originally published at learn.coderslang.com

13 1

JS Test #2: How to create an array in JavaScript

code-snippet
What's the correct way to create an array in JS?

.

.

.

.

.

.

.

.

.

.

.

.

.

The first array, a1 is declared using an empty array literal. There are no issues with it. In fact, it’s one of the most common ways of declaring an array in JS.

The second one, a2 is created by calling Array as a function. It’s fine and it creates an empty array as well.

The third array, a3 is created using an explicit call to the Array constructor as we use the new keyword there.


ANSWER: All arrays are created correctly

Learn Full Stack JavaScript

Top comments (2)

Collapse
 
ruchika30 profile image
Ruchika Sood

cannot see the image of any

Collapse
 
coderslang profile image
Coderslang: Become a Software Engineer

The image is on the cover or learn.coderslang.com

This post blew up on DEV in 2020:

js visualized

🚀⚙️ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! 🥳

Happy coding!

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay