Notes for Javascript

Source: Internet
Author: User

1,Document. Write ("

2. Javascript comments are the same as those in Java: // and /**/.

3. Because Javascript is case sensitive, variable names are also case sensitive. Variables are case sensitive (YAndYIs two different variables.Start with a letter or underline

4,It is recommended to use the VaR statement declaration in Javascript. The value assignment of a variable is the same as that in Java. If the variable you assign a value has not been declared, the variable will be automatically declared, x = 5;

var x=5;var x; 

After the preceding statement is executed, the value of variable X is still 5. When the variable is declared again, the value of X is not reset or cleared.

To add spaces between two strings, you need to insert spaces into one string.

5. supported:

greeting=(visitor=="PRES")?"Dear President ":"Dear ";

If the value in the variable visitor is "pres", the value of "Dear President" is assigned to the variable greeting; otherwise, the value of "dear" is assigned ".

6. Use the equal sign (= ).ComparisonVariable! No equals method. You can use = for string comparison.

7. Create three message boxes in javascript: The alarm box (alert) and the confirmation box (confirm () Prompt box (prompt ()). Details of three message boxes

8. A function with no parameters, parameters, and return values. Document. Write (product (6, 5 ))

9. What is the difference between "" and "" In JavaScript? Single quotes and double quotes cannot be nested. If "get" is ", the first two are considered as one, and the latter is ineffective.

Code Output
\' Single quotes
\" Double quotation marks
\& And number
\\ Backslash
\ N Line Break
\ R Carriage Return
\ T Tab
\ B Escape Character
\ F Page feed

10. Compile the script as a function to avoid executing the script when loading the page. We will not execute the defined function. We will only execute the function when it is called.

11. The lifetime and loop of JavaScript variables are similar to those of Java.

If you declare a variable outside the function, all functions on the page can access the variable. The lifetime of these variables starts after they are declared and ends when the page is closed.

12,For... in declaration is used to traverse the attributes of an array or object (loop operation on attributes of an array or object ).for(VariableinObject) {execute code here}, equivalent to foreach in Java

13. Each element in the webpage can generate events that can trigger JavaScript Functions. For example, when a user clicks a button, an onclick event is generated to trigger a function.

Onload and onUnload (User exit page) onfocus (element gets focus), onblur (element loses focus) and onchange onsubmit (submit form to verify the entire form field) onmouseover and onmouseout try... the catch statement captures the exception throw Declaration to create an exception ). You can use this declaration with the try... catch declaration to control program streams and generate precise error messages.

14. html labels can be used in the document, such as: <br/>, because it will be displayed on the HTML page. Alert () can only be replaced with escape characters, for example: /n, and the HTML code is displayed,

15. onerror event

As long as a script error occurs on the page, an onerror event is generated. To use the onerror event, you must create a function to handle the error. You can call this function onerror event handler ). This event processor uses three parameters to call: MSG (error message), URL (URL of the page where an error occurs), and line (line where an error occurs ).

 

 

 

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.