1. Programming language
html+css markup language
js: lightweight interactive language - > full stack programming language
-
object-oriented:
- C++
- JAVA
- PHP
- C# (.net doc)
- JS
-
Process oriented
- C
java has nothing to do with javascript
2. What parts does JS learn?
- ECMAScript(es)
- DOM: Document Object Model
API (properties and methods) allows JS to get dom elements in the operation page - BOM: browser object model. Provide various APIs for js to operate browser
3. Variable
It is not a specific value, but a container for storing the specific value. The value can be changed.
Based on es syntax specification, js creates variables
- var (es3)
- function (es3) creates a function, which is also a variable, and the stored value is a function type
- let (es6) create variables
- const (es6)
- import module specification based on es6 to export required information
-
Class create a class based on es6
var [Variable name]=Value; var num = 12; let [Variable name]=Value; const [Variable name]=Value; function Function name (){ function Fn(){} } ... var n = 13; n= 14; alert(n+10); =>Pop it out 24, now n For and on behalf of 14; const m = 100; m = 200; =>Assign to constant( var let const Define the difference between variables)
Create variable name: more semantic add/ create / insert / delete(del) / update /remove(rm) / info / detali
- Case sensitive
- Follow the hump writing method, and name according to numbers, letters, underscores, $(numbers cannot be used as the beginning); English naming words are spelled into a complete name, the first word is lowercase, and other meaningful words are capitalized
-
Can't use (special meaning) keyword and (may become keyword in the future) reserved word
var n = 12; var N = 13;//=>Two n's are not the same variable var studentInfo / student_info / _studentInfo (_Underline first, all public variables) $studentInfo (General storage jquery element)
-
Basic data type
- number boolean null string undefined
-
Reference data type
-
object
- Common object {} array object [] regular object / ^ / Date object date
- function
-
-
Unique value of special type symbol added in es6
var n = 13;//=>There is a special value NaN(not a number) in the number 0-13 12.2, indicating that it is not a valid number, but it belongs to the number type var s = '';//=>The quotation marks of '12' {} are all composed of 0 or more characters var b = true;=>Boolean 2 values true and false false [Reference data type] var o = {name : 'Mount Everest',age: 9};//=>Normal objects: braces wrap multiple sets of attributes and attribute values {} empty objects var ary = [12 ,23,24,25] ;//=>Multiple items wrapped in brackets are arrays, 0 to multiple items [] are empty arrays var reg = /-?(\d|([1-9]\d+))(\.\d+)?/g ;=>A complete regularity consisting of metacharacters // It's not regular, it's a single line comment function fn (){ } symbel Created with unique values var a = Symbel ('Mount Everest');=>Symbol('Mount Everest') Symbol Not a string var b = Symbel ('Mount Everest'); "Symbol" Is a string a==b; ->false
-
[code if run]
- Browser kernel to render parsing
- Run v8 engine based rendering based on node and parse js tool / / run the current file based on node through cmd
- [output result]
- Alert: pop up mode browser prompt box window.alert Full name output results are all converted to strings
- alert(1+1);=> '2'
alert ([12,23]);=>'12,23' [12,23].toString() =>"12,23" alert({name: 'xxx'}); =>'[oject Object]' object toString The result is object object What is the object? - confirm : Confirmation prompt box with confirmation and Cancel buttons ```javascript var flag = confirm('Are you sure you want to exit?'); if(flag){ //> flag:true Event confirmation button clicked by the client } else { //> flag:false Click the Cancel button } ``` - prompt :stay confirm Add input box on the basis var num =12; var flag =prompt(num); alert(flag); - console.log: Enter the log in the browser console( fn+f12) /* Shortcut key: num.log TAB*/ + Elements:Display and modify elements and styles in the current page + consloe :Console, js In code.log Output here, or write directly js + console.dir : than log Output more details (when outputting object data values) - console.table: hold json Data output in tabular form - console.log(' Normal output~ '); console.warn(' Output warning! '); console.error(' Output error!!! ');