JavaScript Getting Started Tutorial

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators

Introduction to JavaScript

JavaScript is an object-and event-driven scripting language that is primarily applied to the client.

Characteristics:

    • Interactivity (What it can do is dynamic interaction of information)
    • Security (does not allow direct access to local hard disks)
    • Cross-platform (as long as the browser can interpret JavaScript can be executed, and platform-independent)

JavaScript is different from Java

    • JS is Netscape Company's products, formerly known as Livescript;java is the product of the Sun company, is now the Oracle company's products.
    • JS is Object-based and Java is object-oriented.
    • JS can be executed simply by explanation , and Java needs to be compiled into a bytecode file before execution.
    • JS is a weak type and Java is strongly typed.

How JavaScript is combined with HTML

You want to incorporate other code into your HTML, all in the form of a label.

    • Store JavaScript code in tag pair <script> JS code ... </script>
    • Encapsulates JavaScript code into a JS file and imports it through the SRC attribute in <script>

Note: If the SRC attribute is used in the <script> tag, the JavaScript code stored in the tag will not be executed. So usually the import JS file is done with a separate <script>.

JavaScript syntax

Each language has its own grammar rules, JS syntax and Java is very similar, so it is easier to learn. JS also has the same variables, statements, functions, arrays and other common language elements.

    • Variable

defined by the keyword Var, the weak type is not specifying a specific data type.

For example: var x = 3; x = "Hello";

Note: JS in the special constant value: undefined. When a variable is used without initialization, the value of the variable is undefined (undefined). Only strings in JS have no characters, so "," is the same function.

Note: JavaScript statements at the end of the sentence can be terminated without semicolons, the characteristics of non-rigorous language. But in order to conform to the programming specification, you need to define the Terminator like Java. And in some cases, you must write a semicolon, such as: var x = 3; var y = 5 If the two statements are written on the same line, a semicolon is required to separate them.

    • Operator

Arithmetic operators (+-*/% + +-), assignment operators, comparison operators, logical operators, bitwise operators, ternary operators.

The operators in JavaScript are roughly the same as Java. Just a few points to note during the operation:

      1. var x = 3120/1000*1000; x = 3120 instead of 3000
      2. var x = 2.4 + 3.6; x = 6 instead of 6.0
      3. var x = "12" + 1; x = "121" Because the plus sign is a connector for a string
      4. && | | is the logical operator,& | is a bitwise operator
      5. Ternary operators are also supported
      6. Special operator typeof: A string that returns the data type of an action expression.
   var x = 3;   var y = "123";   var z = false;   typeof (X); Number   typeof (Y);//String   typeof (z);//Boolean;

  

JavaScript Getting Started Tutorial

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.