First, The history of JavaScript
1992 Nombas developed the embedded scripting language for C-minus-minus (c--) (originally bundled in Cenvi software). Rename it scriptease. (The language that the client executes)
Netscape (Netscape) received Nombas's philosophy, (Brendan Eich) developed a set of Netscape scripting languages in its Navigator livescript 2.0 product. Sun and Netscape are done together. And then the name is JavaScript.
Microsoft then emulated a JavaScript clone called JScript in its IE3.0 product.
To unify the three, the ECMA (European Computer Manufacturing Association) defines the ECMA-262 specification. The International Organization for Standardization (ISO/IEC) also adopted ECMAScript as the standard (iso/iec-16262). Since then, Web browsers have struggled (albeit with varying degrees of success and failure) to ECMAScript as the basis for JAVASCRIPT implementations. ECMAScript is the norm.
Second, ECMAScript
Although ECMAScript is an important standard, it is not the only part of JavaScript, and certainly not the only one that is standardized. In fact, a complete JavaScript implementation is made up of the following 3 different parts:
- Core (ECMAScript)
- Document Object Model (DOM) Documents object models (consolidated js,css,html)
- Browser object models (BOM) Broswer object Model (integrated JS and browser)
- The vast majority of Javascript in development is object-based. It is also object-oriented.
To put it simply, ECMAScript describes the following:
- Grammar
- Type
- Statement
- Key words
- Reserved words
- Operator
- Object (encapsulates inherited polymorphism) object-based language. Use an object.
Third, JavaScript basics
1.How to introduce JS
//1. Use javascript: prefix to build URLs that execute JavaScript code<ahref= "Javascript:alert" ("JS has been run ");>Running JavaScript</a>//2. Use<Script> </Script>include<Script>Alert ("JS is running");</Script>//3. Importing JavaScript files<Scriptsrc= "Test.js"type= "Text/javascript"></Script>
2.JS Variable
1. JavaScript is a weakly typed language, which can be used directly before using a variable, without having to define it. To sum up, JavaScript supports two ways to introduce variables.
Implicit definition: Assigns a value directly to a variable.
Display definition: Use the var keyword to define a variable.
2. a row can declare multiple variables. And can be of different types
3. variable name, the first character can only be letters, underscores, $ US dollar symbol Three select one, the remaining characters can be underscores, dollar signs or any alphanumeric characters and case-sensitive, x and X are two variables
3. Constants and identifiers
Constants : Data values that appear directly in the program
Identifier:
- Consists of letters, numbers, underscores (_), Dollar signs ($) that do not begin with a number
- A name commonly used to denote functions, variables, etc.
- For example: _ABC, $ABC, abc,abc123 is an identifier, and 1ABC is not
- Words that represent a particular meaning in the JavaScript language are called reserved words and do not allow programs to be redefined as identifiers
Data type of 4.JS
// 1.JavaScript Basic data Types Number // numeric type boolean // boolean string // String Type // undefined NULL // Object // 2.JavaScript composite data Types Object // objects array // Arrays
Number type:
- Integer and floating-point values are not distinguished;
String type (String):
is a sequence of Unicode characters, numbers, punctuation marks, string constants are enclosed in single or double quotation marks, and there are no character types in JavaScript, and expressions of common special characters in strings;
Some special characters in a string must be accompanied by a right dash \; Common escape character \ n: newline \ ': single quote \ ': double quote \ \: Right Dash
Boolean type (Bolean):
The Boolean type has only two values: True and False, also representing 1 and 0, in the actual operation True=1,false=0
Boolean values can also be considered on/off, yes/no, 1/0 correspondence True/false
The Boolean value is primarily used for JavaScript control statements, such as:
var x = 2; if (x = = 1 ) { alert ("1") ;} Else { alert ("2") ;}
Null and undefined types
Undefined type
The 1.Undefined type has only one value, which is Undefined. When the declared variable is not initialized, the default value of the variable is undefined.
2. When the function has no definite return value, the returned value is also "undefined";
Null type
Another type with only one value is null, and it has only one private value, NULL, which is its literal. The value undefined is actually derived from the value null, so ECMAScript defines them as equal.
Although the two values are equal, they have different meanings. Undefined is a value that is assigned to a variable when it is declared but not initialized, and null is used to represent an object that does not already exist (this is briefly described when discussing the typeof operator). If the function or method is to return an object, the object returned is usually null when it is not found.
Iv. operators
Operator classification
// 1. Arithmetic operator + - * / % + +- -// 2. Comparison operators > >= < <= = = = = = = = !==// 3. Logical operators && | | ! // 4. Assignment operator = + = = *= /=
JS differs from Python and is a weakly typed language
the ability to convert data is called weakly-typed Console.log (' 1 ' ==1) // Trueconsole.log (' 1 ' ===1) //False strongly typed print (// False
1 static type language 23 Dynamic type language 45 Strong type language 67 weakly typed language 81 types can be ignored languages, Contrary to strong type. JS is a weak type. In JS, the string ' 12 ' and the integer 3 can be concatenated to get the string ' 123 ', which can then be treatedas an integer 123 9 so Python is not only a dynamic type language (because it does not use the display data type declaration), but also a strongly typed language ( Because as long as a variable gets a data type, it's actually always the type.
static dynamic, strongly typed weakly typed
V. Process Control
- Sequential structure (executed from top to bottom)
- Branching structure
- Loop structure
Branching structure:
1. If.....else Structure:
if (expression 1) { statement 1;} Else if (expression 2) { statement 2;} Else if (expression 3) { else{ statement 4;}
2.switch-case structure
Switch Basic format Switch (expression) { case value 1: statement 1; break; Case value 2: statement 2; Break ; Case Value 3: statement 3; Break ; default : statement 4;}
Switch is more concise and clear than the else if structure, making the program more readable and more efficient.
Looping statements
For loop: (recommended)
syntax rules: for (initial expression; conditional expression; self-increment or self-subtraction) { EXECUTE statement ... }
03.JavaScript Brief Introduction