JavaScript What is it?
*
JavaScript Is one of the most popular languages in the world. It is a scripting language running on the client (Script It means script )
*
scripting language : No compilation required , During operation by js interpreter (js engine ) Explain and execute line by line
*
Now it can also be based on Nodejs Technology for server-side programming
1.3 JavaScript Role of
Form dynamic verification ( Password strength detection )(JS Produce the original purpose ) Web effects Server development (Node.js) Desktop program (Electron) App(Cordova)
Control hardware - Internet of things (Ruff) Game development (cocos2d-js)
HTML / CSS / JS relationship
html /css Markup Language -- Description Language
*
HTML Determine the structure and content of the web page ( Decide what to see ) Equivalent to human body
*
CSS Determine what the web page looks like to users ( Decide whether it looks good or not ) It's equivalent to dressing people , Make up
JS scripting language --- Programming language
*
Realize business logic and page control ( Decision function ) It is equivalent to various human actions
Browser execution JS
The browser is divided into two parts , Rendering engine and JD engine
*
rendering engine : To analyze HTML And CSS, Commonly known as kernel , such as chrome Browser blink, Old version webkit
*
JS engine : also known as JS interpreter . Used to read in web pages JavaScript code , Run after processing it , such as chrome Browser V8
The browser itself does not execute JS code , But through built-in JavaScript engine ( interpreter ) To execute JS code .JS
When the engine executes the code, it explains the source code of each sentence line by line ( Convert to machine language ), Then it is executed by the computer , therefore JavaScript Languages are classified as scripting languages , Will explain and execute line by line .
ECMAScirpt
By ECMA international ( Former European Computer Manufacturers Association ) A programming language for standardization , This language is widely used on the world wide web , It is often called JavaScript or JScript
But in fact, the latter two are ECMAScript Implementation and extension of language
ECMAScript: Stipulated JS Programming syntax and basic core knowledge , It is a set that all browser manufacturers abide by JS Grammar industry standard
DOM—— Document to object model
Document object model , yes W3C Standard programming interface recommended by the organization for handling extensible markup language
adopt DOM The interface provided can operate various elements on the page ( size , colour , Location, etc )
BOM—— Browser object model
BOM Refers to the browser object model , He listened to content independent , Object structure that can interact with browser window . adopt BOM You can manipulate the browser window , For example, pop-up box , Control browser jump , Obtain resolution, etc .
JS First experience
JS There are three writing positions , In line , Embedded , external
Inline JS
<input type="button" value=" Let me try " onclick ="alert('hello world')"/>
*
Single line or small amount JS The code is written in html In the time attribute of the tag ( with on Properties at the beginning ) as :onclick
*
Pay attention to the use of single and double quotation marks : stay Html We recommend using double quotation marks in ,JS We recommend using single quotes
*
Poor readability , stay html Written in JS When a lot of code , Inconvenient to read
*
Quotation marks are fallible , When multiple nested matching of quotation marks , It's very confusing
*
Use under special circumstances
Embedded JS
<script>
alert ('hello world~!') ;
</script>
*
Multiple lines can be JS Code write <script> In label
*
Embedded JS Common ways of learning
external JS file
<script src="my.js></script>"
*
benefit HTML Page code structure , Put a large section JS Code independent to HTML Off page , It is beautiful and convenient
*
Reference external JS Document script No code can be written in the tag
*
Suitable for JS Large amount of code
JS notes
There are two kinds Single-Line Comments // Two backslashes Two line comment /* */
Can be vscode Override of shortcut key settings in settings
JavaScript Output statement
In order to facilitate the input and output of information ,JS Some input and output statements are provided in , The commonly used statements are as follows :
alert(msg) Browser pop-up alert box
console.log(msg) Browser console printout information
prompt(into) Browser pop-up input box , User can enter
Technology
Daily Recommendation