Javascript is a prototype-inherited object-oriented dynamic type case-sensitive client-side scripting language developed from Netscape's LiveScript. The main purpose is to solve the problem of server-side languages, such as Perl. , remaining speed issues, providing customers with a smoother browsing effect.
At that time, the server needed to verify the data. Since the network speed was very slow, only 28.8kbps, the verification step wasted too much time. So Netscape's browser Navigator added Javascript to provide basic functions of data verification. The official name of JavaScript is "ECMAScript". This standard is developed and maintained by the ECMA organization. ECMA-262 is the official JavaScript standard. This standard is based on JavaScript (Netscape) and JScript (Microsoft).
Brendan Eich of Netscape (Navigator 2.0) invented this language, which has appeared in all Netscape and Microsoft browsers since 1996. Development of ECMA-262 began in 1996, and in July 1997, the ECMA General Assembly adopted its first version.
The components of JavaScript include ECMAScript
, DOM
, and BOM
.
JS is a small script statement that runs on the browser, which can realize web page text content animation, dynamic data changes, animation special effects, etc.
ECMAScript
is a scripting language standardized by the European Computer Manufacturers Association (ECMA) through ECMA-262. Simply put, ECMAScript describes syntax, types, statements, keywords, reserved words, operators and objects. It defines all the properties, methods and objects of the scripting language.
DOM
plans the entire page into a document composed of node layers. It is not related to browsers, platforms, and languages. It provides web developers with a standard to access data, scripts, and presentation layer objects in the site. DOM programming can implement web content The effect of verification and dynamic changes
BOM
is a feature of the browser, which can access and operate the browser window, such as moving, closing the window, adjusting the window size, supporting cookies, etc. BOM programming can achieve the effect of dynamically controlling the behavior of the browser itself
. Some people also say this:
ECMAScript can be understood as the basic syntax part of JS.
The DOM can be simply understood as the programming BOM that uses the document object to operate the document content
and can be understood as the programming that uses the window object to operate the browser behavior
.Features
JS runs on the browser a scripting language
1. Script language
Script language is a simple program that is small in scale, does not require compilation, and runs quickly. It is composed of some ASCII characters and can be written using any text editor. Scripting language refers to a programming language that is interpreted and executed by an interpreter in a web browser. Every time a program is run, the interpreter will translate the program code into an executable format. Some programming languages (such as C, C++, Java, etc.) must be compiled, and the source code must be compiled into a binary executable file before it can be run. Scripting languages do not need to be compiled in advance, as long as there is a suitable interpreter. implement.
2. Object-based language
Object-oriented has three major characteristics (encapsulation, inheritance, polymorphism) that are indispensable. Usually "object-based" uses objects, but existing object templates cannot be used to generate new object types. In other words, "object-based" does not have the characteristics of inheritance. Without the concept of inheritance, there is no way to talk about "polymorphism".
3. Event-driven
actions that perform certain operations on a web page are called "events", such as pressing the mouse, moving windows, selecting menus, etc. Can be considered an event. When an event occurs, a corresponding event response may be triggered.
4. Simplicity
The variable type is weakly typed and does not use strict data types. var a,b,c; a=123; b="abc"; a=b;
5. Security
JavaScript cannot access the local hard disk, cannot store data on the server, and cannot modify or delete network documents. Information browsing or dynamic interaction can only be achieved through a browser.
6. Cross-platform
JavaScript depends on the browser itself and has nothing to do with the operating platform. As long as the computer has a browser that supports JavaScript (installed with a JavaScript interpreter), the JavaScript program can be correct. implement.
Disadvantages:
Various browsers support JavaScript to varying degrees. Browsers that support JavaScript and browsers that do not fully support JavaScript will have a certain gap in the effect when browsing the same web page with JavaScript scripts, and sometimes it may not even be displayed.
Difference 1: Different companies, different predecessors
JavaScript is a product of Netscape. It is an object- and event-driven interpretive language developed to extend the functions of Netscape Navigator that can be embedded in Web pages. It The predecessor of Java is Live Script; Java is a new generation of object-oriented programming language launched by SUN, which is particularly suitable for Internet application development; the predecessor of Java is Oak language.
Difference 2: Object-based and object-oriented
JavaScript is a scripting language and an object-based language. It itself provides a very rich set of internal objects for designers to use, but does not support inheritance and polymorphism. Java is object-oriented, a true object-oriented language, supporting encapsulation, inheritance and polymorphism.
Difference 3: Variable types are different in strength and weakness.
Java uses strong type variable checking, that is, all variables must be declared as a specified type before compilation. For example: int x=1234; is a weakly typed variable in JavaScript. The var statement is uniformly used and various data type values can be assigned.
Difference 4: The running location is different.
Java runs on the server side, a large programming language, and JS runs on the client (browser), a small-scale scripting language.
HTML, CSS, and JS are both It is the main technology of the front-end, and the three have their own division of labor. HTML can be used to create the main structure of the web page, CSS is used to beautify the web page, and JS is used to add dynamic effects to the web page.
How about the image, my friend.
Inline introduction method:
1. In the head tag, use a pair of script
tags to embed the js code
2. The type attribute does not need to be written
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title>JS introduction method 1</title> <!--Embedded introduction method 1. In the head tag, use a pair of script tags to embed js code 2. The type attribute does not need to be written --> <script type="text/javascript"> //Define a function (method) function fun1 () { //Pop-up message alert("hello word") } </script> </head> <body> <input type="button" value="Click me" onclick="fun1()"/> </body></html>
shortcoming:
1. The JS code we defined can only be used in the current web page, with low code reuse and low maintainability.
2. JS code and HTML code are mixed in one file, with poor readability.
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>JS introduction method 2</title> <!--Linked introduction of external js files 1. Improve code reuse 2. Reduce the difficulty of code maintenance 3. One page can introduce multiple different js files at the same time 4. Once an external end file is introduced in the script tag, it cannot Define inline code in the middle --> <script type="text/javascript" src="js/myjs.js"></script> <script type="text/javascript" src="js/myjs2.js"></script> <script> function fun3() { alert("js introduction method") } </script> </head> <body> <input type="button" value="Click me" onclick="fun1()"/> <input type="button" value="Click me 2" onclick="fun2()"/> <input type="button" value="Click me 3" onclick="fun3()"/> </body></html>
Advantages:
High code reuse, easier to maintain code
Notes:
1. Multiple JS files can be introduced on one page at the same time
2. Each JS file must be introduced using an independent script
tag
3. Embedded and linked introductions cannot use the same tag.