[Reprint] JavaScript language (1)-JavaScript language Overview

Source: Internet
Author: User
1. What is JavaScript?

Javascript is a scripting language based on object and event-driven with secure performance. It is used to link multiple objects on a web page with HTML hypertext markup language and Java scripting language (Java applet) to interact with Web customers, this allows you to develop client applications. It is implemented through embedding or calling in a standard HTML language. Its appearance makes up for the defects of the HTML language. It is a compromise between Java and HTML and has the following basic features:

1. It is a scripting language.

Javascript is a scripting language that uses small program segments for programming. Like other scripting languages, JavaScript is also an explanatory language that provides an easy development process. Its basic structure is similar to C, C ++, VB, and Delphi. But unlike these languages, it needs to be compiled first, but is interpreted row by row during the program running. It is combined with HTML tags to facilitate user operations.

2. Object-based language.

Javascript is an object-based language and can be viewed as an object-oriented language. This means that it can use the created objects. Therefore, many functions can come from the interaction between methods of objects and scripts in the script environment.

3. Simplicity

The simplicity of JavaScript is mainly reflected in: first, it is a simple and compact design based on the Basic Java statements and control flow, which is a very good transition for learning Java. Second, its variable type is weak, and strict data types are not used.

4. Security

Javascript is a security language. It does not allow access to a local hard disk, nor store data on the server. It does not allow modification or deletion of network documents, information Browsing or dynamic interaction can only be achieved through a browser. This effectively prevents data loss.

5. Dynamic

Javascript is dynamic and can respond directly to user or customer input without passing through web service programs. Its response to users is event-driven. An event-driven action is an action generated by an operation on the home page. It is called an event ). For example, pressing the mouse, moving the window, and selecting a menu can all be regarded as events. When an event occurs, it may cause the corresponding event response.

6. cross-platform

Javascript depends on the browser itself and has nothing to do with the operating environment. It can be correctly executed by browsers that can run the computer of the browser and support JavaScript. Thus realizing the dream of "writing once and going all over the world.

In fact, the most outstanding thing about Javascript is that it can do a lot of things with a very small program. There is no need for a high-performance computer. The software only needs a word processing software and a browser. Without a web server channel, you can do everything through your computer.

In summary, JavaScript is a new description language that can be merged into HTML files. The javascript language can respond to user requirement events (such as form input), instead of transmitting data back and forth over the network. Therefore, when a user inputs a data item, it can be directly processed by client applications without being transferred to the server for processing.

JavaScript and Java are very similar, but they are not the same! Java is a much more complex programming language, while Javascript is quite easy to understand. Its creators can focus less on program skills, so many Java features are not supported in Java Script.

Ii. Differences between JavaScript and Java

Although Javascript is closely related to Java, it is two different products developed by two companies. Java is a new-generation object-oriented programming language released by sun, which is especially suitable for Web application development. Javascript is a product of Netscape, the objective is to expand the browser functions of Netscape. It is an object-and event-driven explanatory language embedded in Web pages. Its predecessor is live script; the predecessor of Java is the oak language. The similarities and differences between the two languages are compared as follows:

1. Object-based and object-oriented

Java is a real object-oriented language. Even a simple program must be designed.

Javascript is a scripting language that can be used to create complex software that is unrelated to the network and interacts with users. It is an object-based and event driver-based programming language. Therefore, it provides a wide range of internal objects for designers.

2. Interpretation and compilation

The two languages are executed in different ways in their browsers. Java source code must be compiled before it is passed to the client for execution. Therefore, the client must have a simulator or interpreter on the corresponding platform, it can use compilers or interpreters to compile code independently from a specific platform.

Javascript is an interpreted programming language. Its source code does not need to be compiled before it is sent to the client for execution. Instead, it sends the character code in the text format to the client for interpretation and execution by the browser.

3. Strong variables and weak Variables

The variables used by the two languages are different.
Java uses a strongly typed variable check, that is, all variables must be declared before compilation. For example:
Integer X;
String y;
X = 1234;
X = 4321;
X = 1234 indicates an integer, and y = 4321 indicates a string.
The variable declaration in Javascript uses its weak type. That is, variables do not need to be declared before use, but the interpreter checks their data types at runtime, such:
X = 1234;
Y = "4321 ";
The former indicates that X is its numeric variable, while the latter indicates that Y is a numeric variable.

4. Different Code formats

Java is an HTML-independent format. It must be loaded by referencing external media in HTML, and its code is saved as byte code in an independent document.

JavaScript code is a text character format that can be directly embedded into HTML documents and loaded dynamically. Compiling HTML documents is as convenient as editing text files.

5. Different embedding Methods

In HTML documents, the two programming languages have different identities. Javascript uses <SCRIPT>... </SCRIPT>, while Java uses <APPLET>... </APPLET>.

6. Static and Dynamic Association

Java uses static concatenation, that is, Java object reference must be carried out during compilation, so that the compiler can implement forced type check.

Javascript uses dynamic concatenation, that is, JavaScript Object Reference is checked at runtime. If it is not compiled, the object reference check cannot be implemented.

Iii. Javascript running environment

Java Runtime Environment:

1. software environment:
(1) Windows 95/98 or Windows NT.
(2) Netscape Navigator x.0 or Internet Explorer x.0.
(3) The character editor used to edit HTML documents (WS, WPS, notepad, WordPad, etc.) or HTML document editor.

2. hardware configuration:
First, you must have the basic hardware configuration environment for running Windows 95/98 or Windows NT. Recommended:
(1) The basic memory is 32 MB.
(2) only 256 of the CRT Color is needed, and the resolution is above 640x133.
(3) only 233 less CPU.
(4) mouse and other external settings (as needed ).

4. Compile the first JavaScript Program

The following is an example to compile the first JavaScript program. It shows how JavaScript scripts are embedded in HTML documents.

Test1.html document:
<HTML>
<Head>
<Script language = "JavaScript">
// JavaScript appears here.
Alert ("welcome to visit the Shanxi window website! ");
Alert ("My website is: www.shanxi?#net ");
Alert ("Window of Shanxi, learn about the window of Shanxi! ");
</SCRIPT>
</Head>
</Html>

Note:

(110000test.html is an HTML document whose identification format is standard HTML format;
(2) Like the HTML identification language, JavaScript code is a text that can be viewed by word processing software and appears in the HTML-related area of the description page.
(3) JavaScript code is described by <script language = "JavaScript">... </SCRIPT>. JavaScript scripts can be added between the identifiers <script language = "JavaScript">... </SCRIPT>.
(4) Alert () is a javascript window object method. Its function is to pop up a string with an OK dialog box and display.
(5) pass <! --... // --> MARK Description: if you do not know the JavaScript code browser, all the marks in it will be ignored. If you know it, the result will be executed. Using annotations is a good programming habit, which allows others to understand your language.
(6) JavaScript ends with the </SCRIPT> label.

From the instance analysis above, we can see that writing a javascript program is indeed very easy.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.