JavaScript (1), javascript

Source: Internet
Author: User
Tags bitwise operators script tag

JavaScript (1), javascript
JavaScript Overview
JavaScript is an object-and event-driven scripting language, mainly used on clients.

JavaScript features:

1. Interaction (dynamic information interaction)
2. Security (direct access to the local hard disk is not allowed)
3. cross-platform (any browser that can interpret JavaScript can be used and has nothing to do with the Platform)

Differences between JavaScript and Java:

It should be clear that it has nothing to do with Java
1. JS is based on objects (the content inside is objects), Java is object-oriented (solve the problem with the idea of object-oriented)
2. javascript can be executed only after explanation. Java needs to be compiled into a bytecode file before execution.
3. JS is a weak type (what to put in a space), Java is a strong type (that is, each type of data is defined as a type, and the defined type, divide the space, that is, the specified space can only be placed with corresponding objects)



Combination of JavaScript and Html:

Adding tags to Html
1. JavaScript code is stored in the tag <script>, JS code... </script>

<Strong> <script type = "text/javascript"> // encapsulate the js Code alert ("Hello Javascript"); </script> </strong>

2. when multiple Html pages use the same JS script, the JS Code can be encapsulated into a file, you only need to introduce a js file in the src attribute of the script tag (to facilitate future maintenance and extension)
Note that if the src attribute is defined in the script tag, the TAG content will not be executed,
<Script src = "xxx. js" type = "text/javascript"> </javascript>
Ps: the early attribute of the script tag is "language" and "type.

<Strong> <script type = "text/javascript" src = "js. js "> // import js file/* alert (" Hello Javascript "); not displayed, because Javascript has been imported. javaScript file of js */</script> </strong>

Therefore, the Javascript file is usually imported separately. <Script> it can be written in any html location, but pay attention to the specifications.


JavaScript Syntax:

The syntax content of a general advanced programming language:
1. keyword 2. identifier 3. Comment 4. Variable 5. Calculation Method 6. Statement 7. function 8. array 9. Object

Many js keywords are repeated in java.

Js variables:
The keyword var needs to be used.

<Strong> <script type = "text/javascript"> var x = 1; // js is a weak type and not rigorous. Sometimes, semicolon and var can be written or not written, however, it is necessary to strictly regulate x = "abcd"; // assign a value to the string x = 3.5123; // assign a value to a decimal number, numeric type x = true; // Boolean x = 'a '; // assign a value string. In js, both single and double quotes are strings. Single quotes can be set to double quotes, and double quotes can be set to single cited alert ("x =" + x ); // function. The parameters are displayed in the dialog box. </script> </strong>

OPERATOR:
1. Arithmetic Operators 2. Value assignment operators 3. Comparison 4. Logic 5. bitwise operations 6. Ternary
/* Arithmetic Operator */
<Strong> var x = 315; alert (x/100); var a = 1.8, B = 2.2; alert (a + "+" + B + "=" + (a + B); alert ("10" + 1 ); // display 101 alert ("10"-1); // Display 9. After string 10 is converted to an integer, then minus 1: note that +-alert (true ); // display true. If alert (true + 1), display 2 // in JS, true defaults to 1, not 0, not null; false defaults to 0, alternatively, null alert (2% 5 = 0); // false </strong>

++, -- And other auto-increment and auto-subtraction operations are the same as Java operation rules.

/* Value assignment operator */
<Strong> var a = 3; a + = 1; // a = a + 1; JS does not differentiate elevation issues a * = 2; a/= 3; alert ("a =" + a); </strong>

/* 3. comparison operator */
<Strong> var a = 3; alert (a = 3); // either true or false alert (a> = 1); </strong>

/* 4. logical operators */

Var a = 3; alert (a> 3 & a <10); // double matching is recommended. Double or alert (a> 3 & a <10); // in JS, it is a bit cloud operator, 1, 0 alert (! A); //, false, a is 3, true ,! False a = 0; alert (!! A );

/* 5. bitwise operators & | ^ <>>>>> */
  var a = 6;       alert(a&3);//2        alert(a^3^3);//6        alert(a>>2);        alert(a<<2);        alert(~a);

/* 6. Ternary operator? :*/
 var a = 3,b = 4;        a==b?alert(a):alert(b);//alert(a==b?a:b);

About undefined

Undefined can determine the type of a specific value

/* Undefined: undefined. It is actually a constant value */var x; // alert (x); // undefined // alert (x = undefined ); // true // to obtain the type of the specific value, use typeof to complete alert (typeof ("abc ")); // string type alert (typeof ('x'); // string type alert (typeof (78); // number type alert (typeof (1.235 )); // number alert (typeof (true) = "boolean"); // boolean Type


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.