JavaScript Learning Notes (ii)

Source: Internet
Author: User

Learning content:

I. Definition of variables

Two. js's basic data type

Three. JS's basic syntax

1. Definition of variables:

The most basic thing in any language is a variable, so how to define variables and how to use them is actually a very simple thing.

JS provides a way to define variables, but we need to be clear and aware of things when defining variables.

    • Variables must start with a letter
    • Variables can also start with the $ and _ symbols (although we do not recommend this)
    • Variable names are case sensitive (Y and y are different variables)

The definition of variables in JS has its own way of defining.

varnum1=100;//do not write int        varnum2=200; Sum=num1+num2; //var sum=sum1+sum2;Document.writeln (sum); vars= "JavaScript";//do not write a string        vars1= "HTML"; varS2=S+S1;//+ represents connecting two stringsDocument.writeln (S2); </script></body>

From the above code we can not be difficult to find that JS in the syntax is not as a programming language as the norm, the requirements are not very strict.

And when defining variables, we can only use Var to define, not as in the programming language of the definition of the way, otherwise it will

Error, when writing JS code, the type of the variable we do not have to write out, meaning that there is no need to be written int sum= ...

We just need to write out the Var sum= ... You can have it. As long as the browser knows what type of variable it can be ... So

When defining variables, be sure to pay attention to the way you define them ...

Basic data types for 2.JS

(1) Numerical type

I. Integral type Constants

Hexadecimal starts with 0x, for example 0x88

Octal must start with 0, as in 0123

The first digit in decimal cannot be 0, such as 123

II. Real-Type constants

12.23 5E7 (Scientific counting method) 4e5 et cetera

Iii. Special Values NaN (not numeric) Infinity (infinity)

(2) Boolean type

The Boolean is simple, a true, a false

(3) Character type

The string is just as simple: "ABC"

The special characters in the string need to be represented by a backslash (\) followed by a normal character. such as \ r \ n \ \b \ ' et cetera

Basic syntax for 3.JS-three process Control

Three major Process Control

(1) Sequential control: Sequential control actually refers to the program in order to execute the case ...

(2) Branch control: (1) Single branch (2) Dual Branch (3) Multi-branch

(1) A single branch is

if (conditional expression) {

Statement

}

(2) Two branches are

if (conditional expression) {

Statement

}else{

Statement

}

(3) Multi-branch structure

if (conditional expression) {

Statement

}else if (conditional expression) {

Statement

}else{

Statement

}

//solve 1+ .... 10 of and         varn=10; varSum=0;  for(vari=1;i<=n;i++) {sum+=i;        } document.writeln (sum); //resolved from 1-10 even-numbered and        varn1=10; varSum1=0; varSum2=0;  for(varj=1;j<=n1;j++)
        {            if(j%2==0)            {                sum1+ =j;            } Else             {                sum2+ =j;            }        }        Document.writeln (SUM1);        Document.writeln (sum2);    </script></body>

(3) Loop control section and (1) Do_while loop (2) while loop (3) for Loop (4) for_in loop

(1) Do_while (2) while (3) for (4) for_in (understand)

Do while                      (conditional) for             (Var ... ) for            (variable in object)
{{{{{{{{{{{} code required to execute; code to execute; code to execute; }while (condition ) ;}}}
varn=10; varSum=0;  Do{sum+=N; } while(n--);       Document.writeln (sum); varn1=10; varSum2=0;  while(N1) {sum2+=N1; N1--;       } document.writeln (SUM2); varSum3=0;  for(varj=1;j<=n1;j++)//don't write the int in handy.{sum3+=J;       } document.writeln (SUM3); varA=NewArray (); varx; a[0]=1; a[1]=2; a[2]=3;  for(xincha) {Document.writeln (a[x]); }   </script></body>

These four commonly used are the while and for loops: Actually mastered the two kinds of cycle structure can be ...

JavaScript Learning Notes (ii)

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.