variables, data types, operators, process structures for "Rough Edition" javascript

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators logical operators

The content of this article:

    • Variables for JavaScript
    • Data types for JavaScript
    • The JavaScript operator
    • The process structure of JavaScript

Starting Date: 2018-05-09

Variables for JavaScript

To create a variable:

Global variables: Global variables are variables that can be called everywhere in the JS code

    • "When not in {}" var variable name = value;
    • "Within {}" variable name = value;

Local variables: Local variables are variables that are only valid in the function body

    • "Within {}" var variable name = value;
    • "The parameter variable of a function is also a local variable"

Scope:
    • function body, variable with the same name, local variable precedence above global variable
    • Local variables cannot be called outside the function;
    • In nested functions, the outer function cannot invoke the local variable of the inner function, and the memory function can call the local variable of the outer function.

Add:
    • The scope of a variable is a big pit, and what is the scope chain problem, life cycle problem "for example, the priority of a function name with the same name as a variable is also an unusual problem." Use to be aware. Since this is a simple record, it does not record anything so complex.

Data types for JavaScript

    • JavaScript is a dynamic type of language that uses VAR to declare each object, and the data for each object determines what type of data it is.
    • So the following is mainly about the relationship between data types and variables

Numeric type:
    • Number: Ordinary numbers, can be used in eight, 16 or 16, etc. to indicate, can be a floating point.

Character type:
    • String: The character being "" or "wrapped"

Boolean type:
    • Boolean: There are two values, one is true and one is false;

Reference type:
    • Undefined: A variable that declares a variable but does not have an assignment initialized.
    • Object: Indicates that the variable is an object, and when the variable is assigned null, it represents an empty object.

<! DOCTYPE html>functionF1 () {vartest=6;// Number            varA= "7";//String            varb=true; varC; varD=NULL; vare={' name ': ' Lilei '}; Console.log (typeof(test));// NumberConsole.log (typeof(a));//stringConsole.log (typeof(b));//BooleanConsole.log (typeof(c));//undefinedConsole.log (typeof(d));//ObjectConsole.log (typeof(e));//Object        }    </script> 

Add:
    • Escape problems with strings: You can have some characters in a string that have a specific meaning, such as when \ n is displayed in a Web page and becomes a newline character. If you want to "do not use that special meaning", you need to precede these special characters with \
    • typeof (variable name) can return the data type of the variable.

The JavaScript operator

Arithmetic operators:
    • + addition operator
      • The addition operator, in addition to the function of adding value, can also stitch strings, such as "a" + "B" result is "AB", 7+ "a" result is "7a".
    • -Subtraction operator
    • * Multiplication operator
    • /Division Operator
    • % seek remainder operator
    • + = addition Assignment operator,-= subtraction assignment operator, *= multiplication assignment operator,/= Division assignment operator,%= find remainder assignment operator

Self-increment, decrement operator:
    • + +: The increment operator, based on its own value, adds a
    • ---: The self-subtraction operator, based on its own value, is reduced by one
    • The self-increment, decrement operator can be placed before the variable "increment first, then take the value", can also be located after the variable "first value, then self-increment",

Relational operators:
    • <=: Not greater than operator, for example a <= B, returns True if A is not larger than B, otherwise false
    • <: Less than operator
    • >: Greater than operator
    • >=: not less than operator
    • = =: equals operator
    • !==: Not equal to operator
    • Comparison rules:
      • Between values: Direct comparison of numeric sizes
      • One is the value: convert the other to a value
      • Between strings: Compare the Unicode numeric sizes between them
      • Strings and non-numeric values: Turning non-numeric values into strings
      • Other...

Logical operators:
    • ! : Logical non-operation, reverse the result, return the result is a Boolean value,
    • &&: Logic and operation, return result is Boolean value,
    • || : Logical OR operation, the return result is a Boolean value

Bitwise operators:
    • ~: Bitwise Non-
    • & Bitwise AND
    • | bitwise OR
    • ^ Bitwise XOR OR
    • << left-shift operation
    • >> right shift operation with symbols
    • >>> Unsigned Right shift operation

Other operators:
    • ?:: This is a three-mesh operator, expression (EXPR1)? (EXPR2): (EXPR3). When EXPR1 evaluates to TRUE, the value is EXPR2, and the value is EXPR3 when the EXPR1 evaluates to FALSE.

The process structure of JavaScript

Loop structure:
    • While structure
      • while (conditional expression) {Loop execution code snippet}
    • Do-while structure
      • do{Loop Execution Code snippet}while (conditional expression);
      • Do-while Cycle executes once if the initial conditions are true
    • For structure
      • for (loop variable = initial value; loop condition; counter) {Loop execution code snippet}
    • For-each structure
      • for (loop variable in collection) {Loop execution code snippet}

Select structure
    • If
      • if (conditional expression 1) {conditional expression 1 is true when executing code}else if (conditional representation 2) {conditional expression 2 is true when code executed}else{previous condition is not compliant}
      • else if and else are optional
    • Switch
      • Switch (value) {Case value 1: Code snippet; break;case value 2: Code snippet; break;case value 3: Code snippet; Break;......default: code snippet;}

Concluding sentence:
    • Return: Ends the run of the function body where return is located. and returns the value followed by return.
    • Break: Ends the loop where the break is located. Break can also be used by switch to jump out of a selection, and the other case will be executed down without a break.
    • Continue: End this loop early in the continue position, and then perform the Next loop judgment.

variables, data types, operators, process structures for "Rough Edition" javascript

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.