Some basic essays on JS

Source: Internet
Author: User
Tags script tag what operator

JSBasic

01, JS

API: someone else is ready for something that we are responsible for using.

Ability to write all code independently.

After five days, the code is written again.

Ask questions after 10 days.

The problem is marked with red

02, JS is divided into three parts, grammar, annotation (summary), asynchronous and synchronous (simple introduction), Exchange two variable value,

The naming conventions must obey, type conversions, operators, process Controls.

Focus

03. shortcut keys

Waiting to be added

04. Browser

Five big browsers: chrome, firefox, safari, ie (*), Opera.

Browser compatibility issues (important)

The test only tests these five (chrome, firefox, ie are the focus).

The parser specifically parses the Code.

The browser has the ability to store Data. Saving the data is Deleted.

The browser is responsible for the functions of the Unicom Network.

Everything in the browser is Drawn.

05. JS Composition and Features

    1. Composition

Three-part Ecmascript-basic Grammar Objects (syntax and basic objects)

Dom:document Object Model Document objects (methods and interfaces for Content)

Bom:broswer Object Model Explorer (interactive methods and Interfaces)

    1. JS is a script (the code does not need to compile (translate the code into a computer-aware Binary) to execute directly, side-resolution execution), weak class, dynamic type, explanatory language.

Int num=10; Double num2=20.9; Coercion Type Language.

Var num=10; Weakly typed language.

Dynamic type: recognize what type of current variable is.

Cross-platform.

Can be embedded directly into the Html.

JS----livescript

JS is not related to Java

Official name ECMAScript

06, the original purpose: to solve the browser and server interaction problems (such as: Authentication Password)

Now: Special effects, games, Mobile Development.

07, HTML function Display Information.

CSS is a landscaping page.

JS implements browser and server interaction with the ability to compute and interact.

08, can directly write in Notepad directly.

JS point out of things may not be able to use, can not come out of things may be available. Object

Dynamic language: determines the type at run Time.

09. Precautions:

1, the declaration of variables are case-sensitive

2, weakly typed language declaration variables are used VAR

3. Strings are represented by single or double quotation marks (single and double quotes in js). Double quotation marks are Recommended. Use single quotes when combined with Dom)

4, each line of code end with a semicolon

10. Comment Line comment//

Multi-line comment/**/

HTML <!---->

css/**/

11, JS Code: write in the script tag, can be written in the HTML page anywhere, generally placed in the body tag Inside. Improve the user experience (script can have many pairs in the Page.) )

12. Script Use

    1. inline, embedded in HTML tags
    2. Internal references, Writing JS code on the page
    3. External references, <script src= "..." >

13, if the code in the script tag error, or affect the code execution of the pair, will not affect the subsequent code Execution.

Do not write code in the introduction of external js.

Inline styles are not easy to develop.

14. Asynchronous and synchronous

Synchronization: a person in order to do more than one thing (a line to Show)

Async: multiple people do more than one thing async (download a file as soon as it is loaded, and execute it immediately after Download) defer (full download is performed) the value of their property is themselves, generally in HTML if the value of the property is itself, the value can be omitted.

Write type= "javascript" can be omitted in H5

15. Variable Exchange (3 Kinds)

1. Ways of Third-party variables

var num1=10;

var num2=20;

var temp=num1;

num1=num2;

num2=temp;

Console.log (num1,num2);

2. Use subtraction

var num1=10;

var num2=20;

num1=num1+num2;

num2=num1-num2;

num1=num1-num2;

Console.log (num1,num2);

3, bit arithmetic

var num1=10;

var num2=20;

num1=num1^num2;

num2=num1^num2;

num1=num1^num2;

Console.log (num1.num2);

The difference is one of the same zero

16. Specification of variable name (subject to Compliance)

There are captions underlined or $ starts, and the middle contains letters, underscores, $, and Numbers. (try not to start with $)

Variable name to make sense, the best word, if the word will not use pinyin, never use Shorthand.

Variable names are lowercase, and multiple words are combined using the hump METHOD.

Recognize that variable declarations are correct: variable declarations can be declared more than once. It is also legal to declare and assign values First.

Initialization of a variable: declares that the variable is Assigned.

17, data Type: JS in the original data type "number,string,boolean,null,undefined,object"

null and undefined only one value is their own,

Boollen:true and False 1 or 0 true or borrowed Var sex=1;//male var Sex=0;//female

When undefined or there is no explicit return value, the value of the variable is Undefined.

Displays the type of the Variable: typeof variable name typeof (variable Name)

If you want to use a variable, it is best to first determine whether the type of the variable is null or undefined

The typeof output is a string.

Number Type: If the value of a variable is 8/10/16 (16 binary has the letter 0xa) 020 (0 starts with Octal)

Do not validate decimals with Decimals.

JS has a maximum minimum value

String: You can use single double quotation marks. The string has Immutability. Not show up. )

18. Translation Characters

19, string concatenation (str1+str2) (a string plus a number is also stitching, a number minus a string (inside is a number) is a number).

20. Boolean type

Ture and False

Console.log (Boolean ());

Number Non 0-turn Boolean is true,0 to False

Non-empty string Goto boolean true, empty string is false, space is true

Underfined and Null are also false

The object is also True.

A Process Control statement with a Boolean type

Boolean is false when a variable is not assigned (undefined) (when A variable is declared Uninitialized)

21. Data type conversion (requires This value to be converted)

1. Other types of turn number types

Number (variable) only recognize numbers, and remove the previous 0.

parseint (variable) digits can be converted (into Integers) at the Beginning. The Non-numeric is Nan true for Nan.

parsefloat (variable), automatically remove the previous 0.

Decimal to Integer do not dry, easy to lose Data.

2. Other type to String type

To splice the display output

Variable. toString ();

A String (variable);

Null can also not be converted to a string in the first way, but the second way Can.

undefinded cannot convert String.

3. Other types turn to Boolean type

22. Arithmetic operator +-*/%

first, an expression, an expression that is concatenated by the arithmetic Operator.

Unary operator + +--num++ ++num An expression that is concatenated by a unary operator (only one operand can Operate)

var num=10;

var num2=num1++ +10; (after + +, first operation plus 1////+ +, first add 1 after Operation)

Binary operator: An expression joined by a two-tuple operator

Ternary operator: ... :。。。

What expression is the expression that is linked with what operator

23. Composite operator

var num=10;

num+=5; Num%=3

Console.log (num);

24. comparison operator <><=>= = = = = = = =!==

The result of a comparison operation expression is a Boolean type

25. Logical Operators && | | ! Boolean type if logical operator is used

The result of a logical operation expression (which can be doped with a comparison operation Expression) is a Boolean type

&& is a short-circuit operation, if the preceding expression is false, the direct is false

Result is Object

26. Precedence of Operators

27, Process Control (control code execution order) Three kinds of basic structure

1. Sequential structure: from top to bottom, from left to right (right to Left)

2. Branch structure if, if-else, switch-case, ternary expressions

A, If statement (execution procedure: first to determine whether the result of the expression is true or false, if True then execute the code inside, otherwise execute the following Content)

B, If-else (If (expression) {

Code 1

}else{

Code 2

If true, code 1 is executed, otherwise code 2)

C, Ternary Expressions (expression 1?) Expression 2: expression 3;)

D, If-else If (if-else can have more than one)

28. Comments

Single-line comments are usually on one line

Multiline annotations are typically used on functions, methods, and constructors

Some basic essays on JS

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.