October 23, 2015 JS notes

Source: Internet
Author: User

ECMAScript standard: JavaScript core syntax

Microsoft: Jscript

ECMAScript Standard: Dead Letter

JavaScript and JSCRITP all claim to be fully realized.

ECMAScript standard

W3c:dom Standard: A unified standard for manipulating HTML elements, CSS styles, and events.

BOM: A tool that specializes in manipulating browser windows.

No standard, implemented by browser vendors themselves.

Javascript=ecmascript (core syntax) +dom (Operation Web page content) +bom (Operation browser window, rarely used)

Mozilla→firefox

Jser biggest challenge: Browser compatibility issues

Typical JavaScript uses:

    1. Client data calculation
    2. Client form Validation
    3. Animation

JavaScript Features:

Plain text; explanation execution; weak type; object-based

    1. Use the browser's own JS interpreter:

f12→ Console

Write script code at the cursor, enter execution.

Console: Refers to the console: A window that specializes in debugging the output of a program.

LOG: A feature provided by console console: output a single line of logs to the console

Multiple lines: shift+enter→ line break

Case-sensitive in **javascript! **

* * String single double quotes are OK * *

    1. Install specialized interpreter software separately:

node. js Chrome V8

Win Key +r→cmd→node

Exit: two times Crtl+c

Execute the. js file: 1. CD to the path where the. js file is located

2.node file name Enter,.

    1. Run with the webpage:

The browser consists of two tools:

Typesetting engine: Loading HTML content and CSS styles specifically

EXPLANATION Engine: Run JS script specifically

<script></script> special elements for saving JS script blocks

When does the <script> script block run? Loaded with the page to interpret the execution.

<script> must use the JS syntax!

HTML element in the event "Properties":

What is an event? Elements can respond to different interactions based on different actions of the mouse or keyboard.

<script> interpretation execution, read before execution. Read first to execute first. The sequencing of <script> placement affects the program results.

Optimization: Placed at the end of body

Once defined, used everywhere, one modification, everywhere effective!

Workaround: All code blocks that are repeatedly written are encapsulated as a method:

Method: A sequence of code that performs a specialized function.

Defined in <script> under

Syntax: Function method name () {code block for reuse}

Call: Method name () → Execute immediately after call.

* Do not call do not execute *

Commissioning: But? debug! debugging encountered a problem? Then solve the problem!

As long as there is no response or effect is wrong! →f12

See the cause of the error → Locate the wrong location!

The error in the <script> script block only affects script execution after "location" in the "Current script block" error, and does not affect other element loading or script block execution other than <script>.

Error in Funcition: Can only be started when the method is called!

Page internal Script block problem: Only the current page is available!

FIX: External. js file!

What is the. js file: A file dedicated to saving JS script source code.

The source code must be placed in the JS interpreter to execute, cannot double-click.

How to use the. js file?

    1. Create a. js file, write the source code
    2. Introduce an external. js file in the page

Inside and outside of the same name method, interpretation of execution!

ECMAScript: Case-sensitive, strings must be wrapped in quotation marks (single and double), and semicolons are suggested at the end of each statement.

Statement: A line of commands that allows a program to do one thing

Script block: Sequence of multiple-line statements

Program: Let the computer simulate the implementation of human ideas

Comments: Code descriptions that are not interpreted to be performed or displayed → for programmers to see. Comments also account for Web traffic! The production process must be removed.

HTML Annotations:<!---->

CSS Comments:/**/

JS Comment://single-line comment/* Multiline comment */

What is a variable? A space for storing data exclusively in memory. The program is running in memory.

When to use variables? As long as the data is stored temporarily in the program, it should be placed in a variable

How do I use variables? Declaring, naming, initializing, and using

Statement: Create a storage space in memory and a name

How to declare? var variable name;

Assignment: Load the data to the right of the equal sign into the variable to the left of the equals sign!

If no value is assigned: JS default assignment is undefined

Naming conventions: see Names and meanings

reserved word/keyword cannot be a variable name

Reserved words: JS has occupied the special meaning of the keyword

Use: Using variable names is equivalent to using data stored directly in variables

The general constants are named in uppercase. Once a constant is created, the value cannot be changed by a special variable.

Animation in the program only recognize the angle does not recognize the radian.

How to use constants: const constant name = constant value;

Emphasis: Only the equals sign can store a new value in the variable, and the normal operation does not change the value of the variable, only the value of the variable.

As long as the Var is declared, the declaration will open up memory space.

The space of the variable with the new name in JS replaces the space of the old variable.

With a few Var, you will create several storage spaces.

Data type: The type of data stored in the variable.

JS is a "weak type": The variable itself has no type, only the value in the variable has the type.

A variable that can repeatedly hold different types of data. Why there are data types: All data in reality is divided into different data types, depending on the purpose.

JavaScript data type: Divided into primitive type and reference type

Primitive Type: Number: Numeric; string: Strings; Boolean: boolean; null: null; undefined: undefined.

Reference types: Object: objects; function: functions; number: Numbers; string: Strings; Boolean: boolean; Data: date; error: errors;

Original type: Data saved in variable local!

Number type: represents everything used for comparisons or mathematical calculations

Number of integers in the program, floating point numbers (decimals in reality)

All numbers in JS are saved with number, no integer type or decimal type.

How do I define a number type value? Non-quoted numeric literals

Rounding errors for numeric types in programs: The program does not accurately represent 1/10, just as the reality cannot accurately represent 1/3!

How to fix: Rounding by a specified number of digits: number. toFixed (number of decimal digits)

Console.log (change.tofixed (2));

The data in the change, rounded by 2 decimal places, because the computer for 0.1 is likely to be countless, and we do not count eleven-thirds, in order to avoid this problem, the need to use this method.

In the future, the scale of the calculation result is very long, which indicates that the rounding error is encountered. Rounded by bit.

String type: Sequence of a string of characters!

Unicode: Character numbering in all language literals

Why: Text cannot be processed because the computer intelligently processes numbers.

The computer processes the Unicode number, which is equivalent to processing the text corresponding to the number.

Escape characters: specifically for nonprinting characters and special symbols

How to use escape characters: \ Special symbols such as: \ n newline \ t tab

If the string content contains special characters that conflict with syntax, use \ to convert to the original

The contents of the string variable once created cannot be changed! If you change, you can only create a new string, discarding the old string.

Written questions:

var str= "Hello";

str=str+ "World";

How many strings are there? A: 3.

Boolean Boolean type: Special data type with only two values: True,,false

When to use Boolean? A Boolean type is used whenever a value is only true or false.

Undefined type: Indicates that a variable was declared only, but never assigned a value. So unassigned variables, the default value is undefined.

The value of the undefined type is also undefined.

Original Type size:

Number: integer 4 bytes, floating point 8 bytes

String: 2 bytes per character

Conversions between data types:

Implicit conversions: Program auto-convert data type (PIT)

Weak type: 1. Variable declarations do not have to qualify data types, and any type of data may be saved in the future.

2. Automatic type conversion between data types

Only consider +: Whenever a string is involved, all types are "" and become strings. If there is no string, it is converted to a numeric calculation. What if I encounter a Boolean type? Then true turns 1,false to 0;

Examples of strings plus numbers:

Cast: A programmer manually converts a type by invoking a specialized function

2 string:x.tostring () → convert x to String type, X can be any type.

2 Number:number (x) → convert any type to number type

String→number:

Convert to Integer: var num=parseint ("str")

Reading the integer part of a string

    1. Reads backwards from the first character.
    2. If you hit the first numeric character, start getting the number, and again touch the character that is not a number (including the decimal point) and stop reading.
    3. If the opening touches a space, ignore.
    4. If you encounter the first non-whitespace character, not the number description cannot be transferred →nan,nan means not a numbers. What is Nan: a number (type) that is not a number (content)

To floating point: Var num=parsefloat ("str")

Reads the floating-point number portion of a string.

The usage is exactly the same as the parseint

The only difference: parsefloat recognize the decimal point, only recognize the first one. and parsefloat if it can be converted into an integer, it will not be converted to a floating point, for example, 25.0, then will be converted to 25,.25 0.25

Prompt ("hint message"): A dialog box dedicated to requesting user input data and collecting data.

var str=prompt ("hint message");

All the data obtained from the page is a string! You must first convert and recalculate.

October 23, 2015 JS notes

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.