Understanding Javascript and interacting with Web customers

Source: Internet
Author: User

Understanding Javascript and interacting with Web customers

JavaScript is a scripting language based on Object and event-driven with secure performance. It is used to connect multiple objects on a Web page with HTML hypertext markup language and Java scripting language (Java applet) to interact with Web customers. The emergence of javascript enables a real-time, dynamic, and interactive relationship between the webpage and the user, so that the webpage contains more active elements and more exciting content. At the same time, javascript is short and concise, and executed on the client, greatly improving the web page browsing speed and interaction capabilities. Follow the footsteps of small editors and continue to pursue BS. Today, small editors and small partners will learn about Javascript.

Before learning Javascript, let's take a look at a small example, "Welcome to the Javascript world". The Code is as follows:

 

  <Script language = "javascript" type = "text/javascript"> // the pop-up message box alert ("huanyin came to the javascript world, start the js journey with me happily '(* pipeline _ Pipeline *)′! "); </Script> the running effect is as follows: 

 

Welcome to the javascript world and start the javascript journey happily with xiaobian. Next, let's take a look at a simple mind map, which is a beginner knowledge point of js, such:

Next, let's take a look at the common problems in Javascript. There are eight common problems in js. Let's take a look at these common problems in detail.

First: case sensitive;

In fact, this part of content is mainly used to distinguish us from other languages. The language we used earlier: vb is not case sensitive, and the JavaScript we are talking about is case sensitive. JS methods and variables are case sensitive. Therefore, function myFunction {} and function Myfunction () are different. This rule applies to JavaScript core objects such as Array and Object. when defining an Array, the array must start with uppercase. When you write the Array in lowercase, you will find that the font color of the array changes.

 

Second: single quotation marks and double quotation marks;

Single quotation marks and double quotation marks can be used to create strings without special differences in JS. But as a general rule, most Js developers prefer to use single quotes instead of double quotes, but because the XHTML specification requires that all attribute values be enclosed in double quotes. In this way, the single quotation marks are used in JS, and the use of double quotation marks on the XHTML attribute makes the code of the two more convenient and clearer. Single quotation marks can contain double quotation marks. Otherwise, double quotation marks can also contain single quotation marks.

Third: parentheses;

In Javascript, brackets contain two types of semantics: delimiter and expression. For example, the separator: (1 + 3) * 3 = 12. Expression: (function () {}) (); here, a bracket represents the separator, And the other represents the immediate execution of this method.

Fourth: function call and reference;

For example: var foo = example (); varfoo1 = example; the first one is to call the return value of function example to foo, and the second one is to assign reference of function to a value foo1.

Fifth: line feed;

No matter which quotation marks are used to create a string, the string cannot contain a forced line break. To wrap a line, you can add "\" at the end of the line or use the connector "+" at the front of the next line to tell the browser that the upper and lower lines are in a row. For example, the following two small examples are equivalent relations.

 

var temp='
A list' +"
  1. "+'
    • Foo
    • '+"
"; This is the same as the following;

 

 

var temp='
A list '\"
  1. "\'
    • Foo
    • '\"
"; Sixth: semicolon (;); optional;
In Javascript, the end of each line of statements does not have to end with a semicolon, which is optional; the braces inside are also optional. However, to avoid some differences, we strongly recommend that you do not complete these things. Example: Alert ("nihao! "); And alert (" nihao! ") There are no semicolons. There is no difference, but the following small example is completely different.

 

7. overload is not supported;

Although Javascript is also object-oriented, It is not supported here. For example:
Function myFunction (a, B ){};
Function myFunction ()();
Both of them appear in the script code at the same time. Because overload is not supported, the following functions will overwrite the above functions.

Eighth: scope, closure;
Scope: in fact, it is similar to the namespace in code programming. It refers to the code space where an attribute or method has access permissions, that is, the local variables and global variables that we often call. For example:

   function myFunction(){      var temp="dgh";              }

The above temp cannot be accessed outside the function. Closure: it is closely related to the scope. It is a function that can read internal variables of other functions. It can be understood as a function defined inside a function. For example:

 

 

function f1(){      n=999;      function f2(){        alert(n);      }      return f2;    }    var result=f1();    result(); 
Of course, the purpose of closure: one is to read the internal variables of the function mentioned above, and the other is to keep the values of these variables in the memory. For example:

 

 

function f1(){     var n=999;     nAdd=function(){n+=1}     function f2(){       alert(n);     }     return f2;   }   var result=f1();   result(); nAdd();   result();  

 

Result is actually the f2 function of the closure. It runs twice in total. The first value is 999, and the second value is 1000. This proves that the local variable n in function f1 has been stored in the memory and is not automatically cleared after f1 is called. These are both the advantages and defects of the closure, and must be used with caution when using the closure.

Note:This blog post briefly introduces the basic knowledge of javascript, briefly introduces javascript, and then provides a small example. Welcome to the javascript world, then the editor drew a mind map and introduced the basic syntax, common problems, components, and features of javascript from four aspects, focusing on the common problems of javascript, BS learning, unfinished, To be continued ......

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.