ECMAScript "standard. This standard is developed and maintained by ECMA. ECMA-262 is a formal JavaScript standard. This standard is based on JavaScript (Netscape) and JScript (Microsoft). Brendan Eich of Navigator 2.0 invented this language, which has appeared in all Netscape and Microsoft browsers since 1996. The development of ECMA-262 began in 1996, and in July 1997, the ECMA conference adopted its first version. In 1998, this standard became the international ISO standard (ISO/IEC 16262). The standard is still under development. In June 5438+February 2005, ECMA issued ECMA-357 standard (ISO/IEC 22537), which mainly increased the effective support for XML. At present, the latest version of javascript is 4.0.
1, operator
Operators are a series of symbols to complete operations. There are seven categories: assignment operators (=,+=,-=, * =,/=,% =,<,<=,> =, = =, = =! =,! = =), logical operator (||,&; & amp,! ), conditional operation (? :), displacement operator (|,&; ,<& lt,>& gt, ~,) and the string operator (+). Maybe many people don't know what "= =" is. Here, let me explain to you that in javascript, "= =" is an equivalent operator. Comparison rules of equivalent operators: When two operands are of different types, they are converted to the same type, 1) a number and a string, and the string is converted to a number before comparison. 2)true is converted to 1, and false is converted to 0, and comparison is made. 3) An object, an array, a function and a number or string, convert the object, the array and the function into the original type values, and then compare them. (valueOf first, Tostring if it doesn't work) Other types of combinations vary in size. If two operands are of the same type or converted to the same type: 1) Two strings: If the characters in the same position are equal, the two strings are the same. 2) Two numbers: If two numbers are the same, they are the same. If one is south, or both are south, it will be different. 3) It is the same whether they are true or false. 4) Two references are the same object, the same function and the same array, so they are equal. If they are not the same object, function and array, then they are different, even if the two objects, functions and arrays can be converted into exactly equal original values. 5) Two are empty, or neither is defined, so they are equal. "= = =" is the same operator, which follows the comparison rules of equivalent operators, but does not perform type conversion on operands, and returns false when the types of two operands are different. Only when the two operands belong to the same type can they be compared according to the comparison rules of equivalent operators. For example, null==undefined will return true, but null = = undefined will return false!
Step 2 show
The combination of operators and operands is called expressions, which are usually divided into four categories: assignment expressions, arithmetic expressions, Boolean expressions and string expressions.
Step 3 make a statement
Javascript programs are composed of several statements, and statements are instructions for writing programs. Javascript provides complete basic programming statements, namely: assignment statement, switch selection statement, while loop statement, for loop statement, for each loop statement, do while loop statement, break loop stop statement, continue loop interrupt statement, with statement, try...catch statement, if statement (if ... otherwise if ...) and let statement.
4. Function
A function is a named statement segment that can be referenced and executed as a whole. Pay attention to the following points when using functions: 1) The function is defined by the keyword function (it can also be constructed by the function constructor); 2) A function defined with the function keyword can be called anywhere within a scope (including before the statement defining the function); However, the function defined with the var keyword must be defined before it can be called; 3) The function name is the name referenced when calling the function, which is case-sensitive, and the function name cannot be misspelled when calling the function; 4) Parameters represent values passed to functions for use or operation, which can be constants, variables or functions. Within the function, all parameters can be accessed through the arguments object (the arguments object is a pseudo array, and the property callee refers to the called function); 5) The return statement is used to return the value of the expression. 6) 6) The yield statement throws an expression and interrupts the execution of the function until the next call to Next. The format of general functions is as follows: function myFunction(params) function expression: var my function = function (params) var my function = function () my function (); //Call function anonymous function, which is often passed as a parameter in other functions: window. addeventlistener ('load ',function(),false);
5. Objectives
An important function of Javascript is the object-oriented function. Through object-based programming, we can develop programs in a more intuitive, modular and reusable way. A set of properties that contain data and methods that manipulate the data contained in the properties are called objects. For example, if you want to set the background color of a webpage, the target object is document, and the attribute name used is bgcolor, such as document.bgcolor="blue ",which means to make the background color blue.
6. Events
The actions generated when users interact with web pages are called events. Events can be triggered by users, page changes, or even events you can't see (such as changes in the progress of Ajax interaction). Most events are triggered by the user's actions, such as: when the user presses the button of the mouse, the click event is generated; If the mouse pointer moves over the link, a mouseover event will be generated, and so on. In Javascript, events are usually used with event handlers. For event handling, W3C's method is to use the addEventListener () function, which has three parameters: event, triggered function and whether to use event capture. For security reasons, it is recommended to always set the third parameter to false;; The traditional method is to define ... events on the Internet, which is to add an "on" before the event parameters in W3C methods. IE's event model uses attachEvent and dettachEvent to bind and delete events. Events in javascript are divided into two stages: capture and bubbling, but traditional binding only supports bubbling events.
7, variables
Such as var myVariable = "a certain value"; Variables have their own types. In the above example, the type of myVariable is string, and the common types supported by javascript are: object: objectarray: arraynumber: number; Boolean: Boolean value with only two values of true and false, which occupies the least memory among all types; Null: null value, and the only value is null; Undefined: Undefined and assigned variables are actually weak variable types in javascript. You gave him a string, and he is also a string. If it is a number, it is plastic. True or false, Boolean (be careful not to put quotation marks, otherwise it will be regarded as a string).
Edit the characteristics of this paragraph
In order to be interactive and contain more active elements, it is necessary to embed other technologies in web pages. Such as: Javascript, VBScript, Document Object Model (DOM), Layers and Cascading Style Sheets (CSS), here mainly Javascript. So what is Javascript? Javascript is a new programming language born to meet the needs of making dynamic web pages, and now it is more and more widely used in making Internet web pages. Javascript is a scripting language, or description language, developed by Netscape. On the basis of HTML, you can use Javascript to develop interactive web pages. The appearance of Javascript makes a real-time, dynamic and interactive relationship between web pages and users, which makes web pages contain more active elements and more exciting content. Running a program written in Javascript requires a browser that can support Javascript language. Netscape Navigator 3.0 and above browsers can support Javascript programs, and Microsoft Internet Explorer 3.0 and above browsers basically support Javascript. Microsoft also has its own Javascript called JScript. Javascript and Jscript are basically the same, but there are some differences in details. Javascript is short and pithy, and executed on the client, which greatly improves the browsing speed and interactive ability of web pages. At the same time, it is a simple programming language specially tailored for making web pages. JavaScript makes web pages more interactive. JavaScript simplifies HTML paragraphs that are repeated regularly and reduces the download time. JavaScript can respond to the user's operation in time and check the submitted form immediately without wasting time submitting it to CGI for verification. The functions of JavaScript are endless, as long as you are creative.
Edit this paragraph development tool
Javascript programs are plain text and do not need to be compiled, so any plain text editor can edit javascript files. Dreamweaver CS5 not only has good code highlighting, but also complete code prompts and error prompts, which is very powerful compared with other editors. Visual Studio 2008 supports javascript debugging, which makes program development more convenient.
Edit the tips for this paragraph.
Usage in web pages
There are two ways to add Javascript to web pages: 1, and add HTML documents directly. This is the most commonly used method, and most web pages containing Javascript adopt this method, such as:
Citation mode
If you already have a Javascript source file (usually with js as the extension), you can use this reference method to improve the utilization of program code. Its basic format is as follows:
Script debugging
JavaScript editor
With the deepening of programming with JavaScript, you will begin to understand the opaque error messages given by JavaScript. Once you understand the mistakes you often make, you will soon know how to avoid them, so that there will be fewer and fewer mistakes in your code. Programming is actually a technology that can make rapid progress over time. But no matter how skilled you become, you still have to spend some time debugging your code. If you have done your homework or have experience in JavaScript programming, you will know that quite a lot of time is spent on debugging. This is normal-it's just one of the things programmers have to do. In fact, according to a lot of research, programmers spend an average of 50% time solving errors in their code. Debugging skills: It is very important to choose a browser according to the prompt information of the browser. Different browsers have different error prompts. Among browsers, firefox and opera are the easiest to understand error messages and find out errors quickly. The detailed error reason and line number are given. Use debugging tools If you are a Firefox user, you can search for some web-developed component recommendations in the webpage where components are added: firebug is an excellent component, which can point out errors in your scripts, check DOM trees, check cookie, ajax communication, and debugging tools for CSS, and Firebug has many extensions. Javascript Debugger This is a debugging tool developed by mozilla. The project code is venkman, which is seamlessly integrated with gecko's javascript parser and has very powerful functions. Clear the browser cache Sometimes when the page is obviously modified, the browser will still use the page in the cache for display. At this time, it is best to forcibly refresh the page to reload the data. If not, clear the cache. If you use firebug to debug output variables, you can easily use console.log () to output the values of variables in the script. Fortunately, firebug also parses your output variables and displays a clear variable structure in the console. If there is no firebug, you can use alert instead, but when there are hundreds of variables to output, you may have to close the browser forcibly. It is also a good solution to put a div for debugging in the web page.