JavaScript (1)

Source: Internet
Author: User
Tags bitwise operators logical operators script tag

JavaScript Overview
JavaScript is an object-and event-driven scripting language that is primarily used by clients

JavaScript Features:

1. Interactivity (dynamic interaction of information)
2. Security (does not allow direct access to local hard disks)
3. Cross-platform (as long as the browser can interpret JavaScript can be used, platform-independent)

The difference between JavaScript and Java:

To be clear, a little relationship with Java is not
1.JS is based on objects (the contents are objects), Java is Object-oriented (consider solving problems with object-oriented thinking)
2.JS can be executed with just an explanation, and Java needs to be compiled into a bytecode file before executing
3.JS is a weak type (make a space want to put what put what), Java is strongly typed (refers to each kind of data is defined a type, and the definition of the type, the space partition, that is, the specified space can only put the corresponding object)



How JavaScript is combined with HTML:

In HTML in a tabbed way
1.JS code stored in tags <script>, js code...</script>

<strong><script type= "Text/javascript" >//package JS code        alert ("Hello JavaScript"); </script></ Strong>

2. When more than one HTML page is used to the same JS script, the JS code can be encapsulated in a file, as long as the SRC attribute of the script tag to introduce a JS file (in order to facilitate future maintenance, extension)
It is important to note that if you define the SRC attribute in the script tag, the contents of the tag will not be executed.
<script src = "xxx.js" type= "Text/javascript" > </javascript>
The Ps:script tag earlier property is language and is now the Type property.

<strong><script type= "Text/javascript" src= "js.js" >//import js file       /*alert ("Hello JavaScript"); Because the js.js JavaScript file has been imported */</script></strong>

Therefore, usually in the import JS file is a separate <script> to complete. <script> can be written anywhere in the HTML, but be aware of the specifications


syntax for javascript:

The syntax content that is usually included in a high-level programming language:
1. Keyword 2. identifier 3. Note 4. Variable 5. Operation Method 6. Statement 7. Function 8. Array 9. Object

JS a lot of keywords and Java repetition

JS variables:
Need to use the keyword var

<strong><script type= "Text/javascript" >       var x = 1;//js is a weak type, and is not rigorous, sometimes semicolons and Var write and do not write, but strict specification       x = " ABCD ";//Assignment string       x = 3.5123;//Assignment Decimal, number type       x = true;//Boolean       x = ' a ';//assignment string, JS in both single-and double-cited, is a string, single-lead can set double-lead, double-lead can set a single-cited       alert ("x =" +x);//function to display specific parameters through a dialog box </script></strong>

Operator:
1. Arithmetic operator 2. Assignment operator 3. Comparison 4. Logic 5. Bit Operation 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, String 10 first becomes an integer, then minus 1: Be sure to note +-        alert (TRUE);//Display True if alert ( TRUE+1), display 2        //In JS, true defaults to 1, not 0, non-null;false default 0, or null        alert (2%5==0);//false</strong>

++,--, self-subtraction, and Java's arithmetic rules

/* Assignment operator */
<strong> var a = 3;        A + = 1;//a = a+1; JS does not differentiate elevation problem         a *= 2;        a/=3;        Alert ("a =" +a);</strong>

/*3. Comparison Operators */
<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);//recommended to use double and. Double or        alert (a>3 & A<10);//single & in JS, is a bit cloud operator, 1,0        alert (!a);//,false,a is 3, is true,! True is 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, is actually a constant value */        var x;        alert (x);//undefined        //alert (x==undefined);//true        //To get the type of its specific value, complete        alert (typeof ("abc") via typeof ;//String Type        alert (typeof (' X ')),//String type        alert (typeof),//number type        alert (typeof (1.235));// Number        alert (typeof (true) = = "Boolean");//boolean type


JavaScript (1)

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.