An introduction to JavaScript
Javascript is a dynamic, weakly typed interpreted high-level compiled language. It is based on prototypes and supports many programming paradigms such as object-oriented and functional programming. It is often called JS
(2) By Brendan Eich. Ache)
(3) Background: JavaScript was born in 1995. Its original intention was to relieve the pressure on the server and provide a form verification function on the client side. The original name was: Mocha (Friction), renamed livescript in the Beta version of Netscape Navigator 2.0 in September 1995, was named JavaScript when deployed in Netscape Navigator 2.0 Beta3 in December of that year
(4) Standards: In November 1996, Netscape formally submitted language standards to ECMA (European Computer Manufacturers Association). In June 1997, ECMA developed the ECMAscript standard specification ECMA_262 based on the JavaScript language. JavaScript has become one of the best-known implementations of ECMAscript.
(5) Composition: JavaScript is composed of ECMAscript + DOM + BOM
(1)ECMAscript: defined by ECMA-262, it provides core syntax functions
(2)DOM: full name Document Bbject Model Document object Model, providing IPA for and operation of web pages
(3)BOM: Full name Browser Object Model, which provides methods and interfaces for interacting with the Browser
2. The writing position of JS code
(1) The inline formula is directly written on the label, which is divided into a label and non-A label
A.a label writing
B. Non-a label: for example
(2) Embedded type can be placed in the body or head tag, preferably at the end of the body tag
(3) external chain to create a.js file to write JS code into the file, in the HTML file call through the call (can call multiple JS files)
3. Comments
(1) Single line comment // comment content
(2) multi-line comment /* comment content */
4. The variable
(1) Definition of variable: A variable is an abstract concept in programming language that can store computed results or representation values (a container that holds data in a program)
Use: In JavaScript, variables need to be declared before being used
Declaration: Use the var keyword to declare variables. If the var keyword is omitted, the variable defaults to a global variable
What it does: Records specific contents and accesses them by variable names
How it works: When the var keyword is used to declare variables, the computer allocates storage space from memory for different types of content
Note:
1. A variable name can store only one value
2. When a variable is assigned a second time, the previous value is overwritten
3. Variable names are case sensitive (js is case sensitive)
(2) naming norms
Identifier: refers to the names of variables, functions, and attributes in JavaScript. In JavaScript, the naming of identifiers is not arbitrary and has corresponding rules and requirements. Here is the convention for naming variables:
(1) Identifiers can be composed of letters, underscores, digits, and $signs
(2) Identifiers cannot start with a number (3) identifiers are case sensitive (4) Identifiers cannot use JavaScript keywords and reserved words
(5) as far as possible to retain semantic naming, the use of camel naming rules by the composition of multiple words, from the second word to begin with the first letter capitalized
5. How JS controls the output
(1) Output to page: document.write (content)
(2) Pop-up window frame display: Alert (content)
(3) Console output: console.log (content)
6. Data types (two main categories: basic data types/complex data types)
1. Number
2. String type (string)
3. Boolean (Boolean)
4. Null type (NULL)
5. Undefined type (undefined)
Complex data types: arrays, objects, functions, regexps, etc
7. Determine the data type
IsNaN () : The value returned by number is either a value or NaN, or true if NaN, or false if otherwise
②typeof variables: the returned value is the data typeof the variable
8. Data type conversion
1) Cast:
①Number ②parseInt 3. ParseFloat
4. Variables. ToString () (undefined and null data types cannot be used)
5.String (variable)
6.Boolean(variable) (only ‘ ‘, 0, null, undefined, NaN bool is false, other types of data are true)
2) Automatic conversion
1. Mathematical operators other than wigs
- Both sides of the operator must be operable numbers
- NaN is returned if either side of the operator is not an operable number
- You can’t add
2. Use addition
- In js, + has; Two meanings
- String concatenation: String concatenation takes place as long as either side of + is a string
- Addition: Math only works if both sides of + are numbers
9. Js operator
1. Arithmetic operators
+ – * / %
2. The assignment operator
= += -= *= /= %=
3. Relational operators
==, ===,! =,! = =, <, >, < =, > =
4. Logical operators
- &&
- I’m going to do and
- The left-hand side of the symbol must be true and the right-hand side must also be true to return true
- As long as one side is not true, false will be returned
- ||
- To perform the operation of or
- Returns true if the left or right side of the symbol is true
- False will only be returned if both sides are false
- !
- I’m going to take the inverse
- If it is true, it becomes false
- If it is false, it becomes true
5) Increment and decrement operation (unary operator)
- ++
-
Let’s do the increment
-
There are two types, pre ++ and post ++
-
Before ++, the value will be automatically +1, before returning
-
After ++, will return the value first, in the automatic +1
- —
- I’m going to subtract
- There are two types, pre — and post —
- Same thing with the ++ operator
Operator priority from high to low
1. () has the highest priority
2. Unary (unary) operators :++, –,!
3. Arithmetic operators: *,/,%, +,-
4. Relational operators :>,>=,<,<=
5. Equality operator :== ===! =! = =
6. Logical operators: first &&, again | |
7. The assignment operator
Formula: monocular arithmetic bit relations, logical ternary after the assignment