Home > Web Front-end > JS Tutorial > body text

JS method to declare a series of (multiple) variables at the same time

怪我咯
Release: 2017-07-06 11:33:48
Original
5466 people have browsed it

This article mainly introduces you to the method of using Javascript to declare a series (that is, multiple) variables. Friends in need can refer to it. Let’s take a look. .

Preface

js declares multiple variables at the same time. We believe that many friends will repeatedly use var to define, so how to implement it in a more scientific way? Well, let's take a look at an article about how to declare variables in js. The specific details are as follows.

I won’t go into the method of declaring variables in JS. Friends who need to learn can click on this article.

We often need to declare several variables in a row. When I was a novice, I did this.

var a=1;
var b={};
var c=[];
var d=...
Copy after login

In fact, we can do this:

var a=1,b=2,c=3,d=4;
Copy after login

That is, use, to separate multiple variables.

This situation without line breaks is only suitable for situations where the variable value is relatively single. If your variable is a function or object, then line breaks are required:

var a=function (){
 var b,c,d;
},
b = {
 b:1,
 a:2
};
Copy after login

This way you can keep writing and maintain good readability. Of course, remember to end with;.

In addition, I want to mention here that I have used several JS compression tools recently, and they are all smart, but they are still not smart enough to automatically merge multiple vars in multiple lines. It becomes a var, so if you want to compress your JS, it is best to use this continuous declaration method. jQuery etc. all use this.

The above is the detailed content of JS method to declare a series of (multiple) variables at the same time. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!