JavaScript is a very popular programming language. Many developers will select JavaScript as the entry language. This article will share with you seven tips on javascript (1 ), if you are interested in javascript skills, learn JavaScript as a very popular programming language. Many developers will select JavaScript as the entry-level language, this article will share with you some useful things such as the Seven Practical JavaScript skills and best practices. In the past, if you want to create an object, you need:
Var car = new Object (); car. color = 'red'; car. wheels =; car. hubcaps = 'spinning'; car. age =; the following method achieves the same effect: var car = {color: 'red', wheels:, hubcaps: 'spinning', age :}
It's much simpler. You don't need to use the name of this object repeatedly.
In this way, the car is defined. You may encounter the invalidUserInSession problem, which is only encountered when you use IE. Remember one thing and do not enclose it on the right.
No.
Another convenient shorthand is for arrays.
The traditional method for defining arrays is as follows:
Var moviesThatNeedBetterWriters = new Array ('Transformers ', 'Transformers', 'Avatar ', 'Indiana Jones'); the abbreviated version is as follows: var moviesThatNeedBetterWriters = ['Transformers ', 'Transformers ', 'Avatar', 'Indiana Jones '];
There is a problem with arrays. In fact, there is no graph group function. But you will often find someone defining the above car, just like this
var car = new Array(); car['colour'] = 'red'; car['wheels'] = ; car['hubcaps'] = 'spinning'; car['age'] = ;
Arrays are not omnipotent; this write is incorrect and confusing. Graph groups are actually object functions, and people confuse these two concepts.
Another cool shorthand method is to use a Trielement conditional symbol.
You don't have to write the following...
var direction; if(x < ){ direction = ; } else { direction = -; }...
You can use the ternary conditional symbol to simplify it:
var direction = x < 200 ? 1 : -1;
If the condition is true, the value following the question mark is used. Otherwise, the value following the colon is used.
The above is the knowledge about the seven major JavaScript skills (I) shared by the script team. We will update the seven major javascript skills (II) in the future.