JavaScript Basics Summary

Source: Internet
Author: User

JavaScript advanced Learning is about object learning, which is based on JavaScript, so let's review the basics of JavaScript before you learn advanced.

First part: Variables

Variables are in every aspect of JavaScript learning and application, and in the variables section we need to know the following:


1 Variable Scope

The scope of a variable is divided into two: global scope and local scope

Global scopes: Refers to the global scope under the script tag.

Global variables: Refers to variables declared at the root node of the script tag as global variables, or window. Variables are also global variables, or variables that are not declared in a function are implicitly declared as global variables.

Local scope: Refers to the inner scope of the function.

Local variable: Refers to a variable declared inside a function.


2 Declaration of variables in advance


When you load HTML code on an HTML page, the declaration of the variable is first promoted to the front of the variable's corresponding scope.


That is, if you call a variable before the variable declaration is assigned, you can only get to the variable but cannot get the assigned value of the variable, the returned undefined.


3 Calls to variables


The invocation of a variable requires two points to be noted:


1. When a local scope invokes a variable, it first looks for a local variable with the corresponding variable name, and if not, the global variable name.


2. A global variable that is implicitly declared in a function needs to be called before the variable can be read in the global scope.


Part II: Data types


The data types noted in JavaScript are divided into basic types and complex types, and there are a number of parts that are included and noted, among which we need to be aware of:


1 Data type classification


Base type: Array, String, Boolean, null,undefined.


Complex Type: Object Type (a collection of key-value pairs): Window,document, array, regular, function, etc.


2 Detection data type


We can use TypeOf to detect different types of data, but several of them are special.


Null detects that the data type is "object", and function detects that the data type is "function".


The data types of other objects are "object", and the underlying data detects the corresponding data types.


3 Data type Conversions


The most important thing in type conversion is the conversion of numbers to and from strings.


Numeric to String: ToString (), + "", String ().


String to Numbers: Number (), Perseint (), parsefloat ().


4 delivery of value types and reference types


A value type is a basic data type, and a reference type is a complex data type, and the value is passed differently.


Delivery of value types: When a pass occurs, the value in one variable is copied to the other variable.


Delivery of reference types: When passing occurs, the address that points to the object is referenced to another variable.


Part III: Operators


There are many types of operators, and we need to know not just which operators, but also what the functions of each operator are.


1 arithmetic operators: +,-, *,/,%,++,--


Note: ++a: Participate in the operation after the first self-addition


a++: First to participate in the operation of the original value, after adding

2 assignment operator: =,+=,-= ....


3 comparison Operators


= = Converts an implicit data type and then determines the value, regardless of the data type


= = = Does not convert an implicit data type, and then judge the data type before judging the value


4 logical operators


&&: If the value on the left is true, the value directly to the right is returned, and if the left value is a false value, the left value is returned directly.


| |: If the value on the left is true, return to the left value directly and return to the right value if the left value is a false value.


Attention:

The values converted to Boolean false are: 0,false,null,undefined,nan, ""


53-tuple operator


Judgment statement? The value of the output at the time of establishment: the value of output when not established;


Part IV: Statements


Statements mainly include the following:


SELECT statement: If,if. Else,if. ElseIf. Else,switch () {case}


Looping statements: While,do. While,for,for. Inch


The use of statements need to be based on the actual situation, in the case of functional satisfaction, depending on the situation to simplify the statement.


Part V: Functions


Functions are used primarily as arguments to functions, return values, and declarations of functions.


1 Parameters of the function


The arguments for the function are divided into formal parameters and arguments:


Formal parameter: Refers to the parameter that is needed inside the function that is defined when the function is declared.


Argument: Refers to the argument passed to the function when the function is called.


2 return value


The presence or absence of the return value is determined by the return


If there is no value returned after returning to the return guard in the function, then we get the return value of undefined. If there is a value after return, the return value obtained is this value.


Note: Return is not executed except for statements declared, because declaration statements are promoted to the front of the job field


3 function Declaration Promotion


Function declarations are promoted to the top of the scope like variable declarations, but if the function declaration and the variable declaration are promoted at the same time, the declaration of the promoted function is promoted after the variable declaration.

JavaScript Basics Summary

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.