JS Basic Learning Caprice

Source: Internet
Author: User

2012 has been contacted JS, give me the impression: This is not a complex language. Perhaps this is the so-called study of the more shallow, the less you use, feel that they will be more of the thing! When you start doing basic exercises, you feel as if you are very simple. But later in the object array to do some of the problems encountered, and then found that they do not really understand JS. First of all, I'm in the Codefordream basic learning situation.

The basic parts of the main learning are: annotation symbols, data types, arithmetic operations, logical terms, judgment statements, loop statements, and function.

The simple thing to say is that, because of the long-term use of other languages, JS for the traversal of the array is actually a little different:

The first thing I did was to stitch the string

1 varArr_string = ['Below is Zhang San's personal information:','\ n','Name:','Zhang San','\ n','Age:',' -'];2 //complete concatenation of strings3 varStr_result ="";4  for(vari =0;i<7; i++){5Str_result + =Arr_string[i];6      }7Console.log (Str_result);

Later I learned that JS traversal can have another method, in fact, the code can be written like this:

1 varArr_string = ['Below is Zhang San's personal information:','\ n','Name:','Zhang San','\ n','Age:',' -'];2 //complete concatenation of strings3 varStr_result ="";4  for(varIincharr_string) {5Str_result + =Arr_string[i];6      }7Console.log (Str_result);

Compared to the if judgment, the feeling is not much different from other languages.

1 varWeather ="Cloudy";2 //write the code about the weather conditions below3  if(Weather = ="Sunny Day"){4Console.log ("let's go shopping!");5 }6 Else if(Weather = ="Cloudy"){7Console.log ("sleep at home!");8 }9 Else if(Weather = ="Cloudy"){TenConsole.log ("Let's watch TV at home ."); One } A ElseConsole.log ("I don't know what to do, either .");

Functions are available in all languages, needless to say, for example, this is a simple area-finding function.

1 varBorder_length =9;2 function Square (a)3 {4     varArea =1; 5Area =border_length*border_length;6A =Area ;7Console.log ('The area of the square with the side length as a is:'+a);8     returnA;9 }Ten varArea=Square (border_length); One  AConsole.log ('The area of the square with the edge length of Border_length is:'+Area ); -Console.log ('the Border_length value is:'+border_length);

JS Basic Learning Caprice

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.