4. JavaScript

Source: Internet
Author: User

First, the concept of javascript: is based on object and event scripting language .

1. Features:

a), security.

b), cross-platform (as long as the browser can interpret JS can be executed, and platform-independent)

2. The difference between JavaScript and Java:

A), JS is Netscape company products, Java is Oracle Company
b), JS is an object-based, Java is object-oriented
c), JS can be executed simply by explanation, Java needs to be compiled into a bytecode file before execution
d), JS is a weak type, Java is a strong type

3, the combination of JavaScript and HTML:

A), JS code stored in the label <script>...</script>
b), using the SRC attribute of the script tag to introduce a JS file (<script type= "Text/javascript" src= "js file" ></script>)

Second, JavaScript syntax:

1.variablesdefined by the keyword Var, the weak type does not need to specify a specific data type(Note: JS in the special constant value undefined, when the variable is not initialized to be used, the value of the variable is undefined)
var V;
v = v + 5;
Alert (v);//result is Nan
2. Statement (same as Java statement format): logical operator:&& | |
If statement:
Note: var x = 3;
if (x==4)//can perform comparison operations
if (x=4)//can be assigned to the operation, but also can be judged
Reason: In JS0 can indicate false, not 0 can represent true (usually 1), so the IF (x=4) result is true.non-null is true,null to False
Switch statement: switch (x), where x can receive a string
Loop statement (while\do...while\for)
For (variable in object) {...}
3. Function:
General functions:Format: Function name (formal parameter ...) {...}
Note: When you call a function that has parameters, but you do not give it a value, the function can run, or you can call a function that has no parameters and pass a value to it.
There is a parameter array object (arguments) in the function that encapsulates the passed parameters in an array
When you define a variable in a function without using the var keyword, the variable becomes a global variable after executing the function.
The function is written at the time of invocation:
var s = method ();//s variable receives the return value of the method function
var s = method;//s and method represent the same function, then the function can also be called by means of S ()
     Anonymous Functions: Format: function () {...} (or simply pass the function directly as a parameter, without encapsulation)
Example: var demo = function () {...}
Call: Demo ();
4.Array
     Features: The length is variable, can save any element (array of elements can be stored in different types)
Definition Format: var arr = new Array ();
Arr[0] = "Hello";
ARR[1] = 1;
ARR[2] = true;

Output: var arr = ["123", at +, true];

4. JavaScript

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.