DEV Community

Natália Catunda
Natália Catunda

Posted on

We are simplifying (literals(arrays and objects)) in Js.

Objects

in Javascript, a literal object is the best way to simplify an object if you don't support idle talk, and if you prefer to go straight to the point.(without initializernew Object();)
you use{} and you have keywords as strings and the value can be data like numbers, strings, arrays, functions, etc...
Below is an example :

const fruit={
name: "apple",
weight:50,
color: "red",
}
Enter fullscreen mode Exit fullscreen mode

Arrays

You also use literal arrays on js, with [], simplifying too in the majority of cases, but you can remember that you just use normal Array when you want to use a specific empty element on your array
Below is an example of Literal Arrays :

const fruits = ["apple", "banana", "orange"];
Enter fullscreen mode Exit fullscreen mode

thanks for reading!
🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄

Top comments (1)

Collapse
 
mccauliflower_99 profile image
Info Comment hidden by post author - thread only accessible via permalink
McCall Tucker

This has been supported in javascript for nearly two decades now.....thanks for the update haha

Some comments have been hidden by the post's author - find out more