How to create many Javascript variables in a single statement?

JavascriptWeb DevelopmentFront End Technology

Declarations in a single line is a better way than creating many JavaScript variables in a single statement. It would be easier to add, remove and update variables with this.

Let’s compare,

var one = "Demo One!";
var two = "Demo Two";
var three = 5;
var four = 30;

Now, let’s add it in one statement and see what happens. Since the line length increases, we need to take it to the next line,

var one = "Demo One!",
    two = "Demo Two",
    three = 5;
    four = 30;

Definitely, the first method is easy, less confusing and should be preferred.

raja
Published on 23-Feb-2018 10:05:55
Advertisements