Seven major JavaScript skills (I) _ javascript skills

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.