What do empty curly braces mean in javascript?

What does {} indicate in javascript? for instance

  var txt={}; 

{} means what?

+4
source share
3 answers

This means an empty object. txt declared as a new object in javascript with no properties. If you want to add properties, you can use this:

 var txt = { prop1: 'value 1', prop2: 'value 2' }; 

and then you can get the values โ€‹โ€‹using txt.prop1 and txt.prop2 .

+10
source

{} means that the variable is initialized to an empty object

so that you can create some internal properties using txt.property = ... or also txt["property"] = ...

or define internal objects using txt.anotherobject = {}

+6
source

He is equal

 var txt = new Object(); 

Creates a new empty object with no properties.

+5
source

Source: https://habr.com/ru/post/1485382/


All Articles