Java Script Foundation One

Source: Internet
Author: User

    1. What is Java Script

    2. How to write, Debug JS

    3. Variable

    4. Data type



I. What is Java Script

HTML: A language that specializes in writing web content, building an overall framework.

CSS: Specifically beautify the language of the Web page style, with "decoration function."

JS: Programming language specifically written for interaction

Interaction: User Action, program handles user's actions, returns processing result

How to run:

Browser: Content typesetting engine JS interpretation engine

Content typesetting engine: software that specifically parses HTML and renders CSS

JS parsing engine: Software that specializes in interpreting and executing JS programs

What are explanations and scripts?

Explanation: Default from top to bottom, read one line, run a line, read the same content, will overwrite the first read.

Scripts: Programs that do not require precompilation to interpret edges

2.JS History:

1955: Netscape and Sun co-developed the JavaScript scripting language and implemented the first version of the JavaScript scripting specification in its Netscape Navigator 2, ja Vascript version 1.0

1957: Launched the ECMA-262 specification version, which defines a new ECMAScript scripting language based on JavaScript.

Among the differences:

ECMAScript: Standard, regulation

Javascript:netscape: Languages implemented in accordance with the ECMAScript standard

JScript: Microsoft complies with ECMAScript standard language

1998: Established, the standard of change became the international ISO standard


3.JavaScript:

Generalized javascript=ecmascript (JS core syntax) +dom (API dedicated to Web content) +bom (API that specifically operates the browser window)

DOM: An API specifically designed to manipulate Web content based on the ES standard.

API: A programming interface that the browser has implemented that developers use directly.

BOM: An API that specializes in browser windows, and is not standard and is defined by each browser.


Characteristics:

1. The code can be written using any text editing tool, similar to C and Java.

2. Without compiling, there is a JavaScript engine explaining execution.

3. Weakly typed languages

4. Object-based


Two. Write and debug:

4. How to Write and debug:

JS script is plain text: written in Deamwaerver

Run the script in 2 categories:

1. Run in a standalone JS interpreter: For example, node. js

2. browser's JS Interpreter

Note: The *JS program is case-sensitive!

* The statements of each program are used;


When to use console: The console is a special place to debug your program!

---write js:2 in the Web page:

1. In

A. Executing with the page load process sequence interpretation

B.

C. outputting a line to a page: write HTML content directly in the BODY element

Use the output function of the page: Docunment.writ ("xxxxxx");

Popup function: Window.alert ("xxxx"); --no alert once, it pops up once.

Each box blocks the browser's loading and program execution process

2. In the event handler function of the element: only a small amount can be written

Events: Changes in the state of the elements triggered by the browser automatically or manually by the user

Event handler function: On event name

The essence is an attribute of the element, and the attribute value is a JS statement

Cases:

<button onclick= " Alert (' ejwpiobhjfipobhsdpfbn ') " > Click to surprise

3. Use an external JS file to store the JS program separately:

1. Create and write a. js file:

All three files must be saved as UTF-8 encoding

2. Introduce the. js file in the page:

---load and execute processes and



Three. * * * variable

What is a variable: storage space for storing a data in memory, and then a name.

When to use: data that is reused in a program is saved first

How to use: Declare assignment values

1. Disclaimer: Create a new variable in memory

How to declare: VAR variable name (declared only, but not assigned, default value is undefined)

Note: 1. Cannot start with a number

2. Cannot use reserved words: JS and pre-used keywords

3. It is best to see the name: such as the name of the hump (first letter lowercase, followed by the first letter of each word capitalized)

2. Assignment: Save the data to the right of the equal sign to the variable to the left of the equal sign

How to assign a value: variable name = value, * Assign a new value to a variable that already contains a value, and the new value will overwrite the old value *

3. Value: As long as the variable name is used, at run time, it is automatically replaced with the value in the variable.

Special Cases: 1. Only declared, but not assigned variables, can be used arbitrarily, output is undefined.

2. Never declare a variable, cannot use, get error prompt uncaught Referenceerror

3. Variables that have never been declared, are not assignable---and VAR

strongly recommended: variables must be declared with Var

Note: as long as the same page, the previous declaration, assignment, can be used later, but no longer ahead of this script

Example 1:


varhb="Spicy Chicken Leg Fort ";
Console.Log(HB);
Box="steamed Bun ";

Console.Log(HB);
Console.Log(Box);

The output is: "Spicy chicken leg fort" "Spicy Chicken leg fort" "Bun"


Declaration in advance: son Ah, before the program is formally executed: the VAR declared variable is declared in advance to the top of the current script block before the program executes. {* * * assignment left in situ}


Four. Constant: Once initialized, the value cannot be changed by the amount.

When to use: In a program, once you define a value that cannot be changed, you must save it with a constant.

How to create: const constant NAME = value; the name to use as a constant is capitalized

Note:


If you insist on changing the value of the constant, no error, but can not modify the success

pi= 3.14 ;
deg= - ;

pi= 1 ; // An error? Impact results?

Results: No error, no impact on results


Five. * * * * data type: The way data is stored in memory

Why there are different data types: The different types of data in the real world have to be used specifically.

Category: 2 Categories: Values of "primitive type" and "Reference type" objects

Primitive type: The value is stored directly in the variable local type

Class 5: Number srting Boolean Undefined Null

Reference type: The value is not stored directly in the variable's local type, but the variable only holds the address value pointing to the location of the actual data

1.Number: Indicates all numbers

How to define: all non-quoted numbers are number type data.

When to use: No quotation marks are given for calculating or comparing numbers.

For example: Age, Price

Occupied space: All numbers are stored in a 64-bit binary number 1byte=8bit

Integers with 32-bit binary storage = 4 bytes

---value is independent of the amount of space occupied

Rounding Error: There are also numbers in the computer that can not be accurately calculated, resulting in a precision deviation of the calculated results, inevitably

Solution: Rounding--n.tofixed (2) by the specified number of decimal places and rounding the calculation results by 2 decimal places

2.String: String representing all text information

How to define: All information used for display is quoted, single and double quotes.

When to use: all the information used for display is quoted, there is no character type in JS, so a word should also be quoted

Space occupied: Letters or numbers, each 1 bytes; 2 bytes per kanji

JS memory is used to store characters in the Unicode number of the string

Unicode: An artificial number for each character in the primary language

Once the string is created, the value cannot be changed, and the old string can only be replaced with a new string.

Special:+ operation, if the participating operations are all strings, then addition becomes string concatenation

3.Boolean: Only two values: true, flase

When to use: As long as the save right/wrong, true/false, set up/not established, are represented by the Boolean type.

How to define: True with no quotes and flase is the Boolean type












Java Script Foundation One

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.