JavaScript Basics 01

Source: Internet
Author: User

JavaScript Basics 01

What can JavaScript do?

Give the page soul, so that the page can move, including dynamic data, dynamic tags, dynamic styles and so on.

such as the implementation of the Carousel diagram, drag, magnifying glass, and so on, and dynamic data is like not without JS page, the whole content is

Write on the page load on the page, but to achieve a certain condition to load the required content, such as waterfall stream pictures,

Dynamic tags, like a chat box, you a word, others a word, and these sections are tagged, let

Add to the page, the dynamic style is like the real effect of the carousel, we all know that the CSS implementation of the carousel is margin or other properties

Make the picture move, and the dynamic style can change the style and make the picture turn.

What is JavaScript?

Avascipt is a scripting language that is interpreted and executed by a Web browser.

JavaScript is a scripting language designed to interact with Web pages and consists of the following three different parts:

1, ecmasript, defined by ECMA-262, provide core language functions;

2. Dom provides methods and interfaces for accessing and manipulating Web page content;

3. BOM provides methods and interfaces for interacting with the browser

How do I apply JavaScript to a Web page?

Method One: Insert the JavaScript code into the <script> tab of the HTML Document

Method Two: Store the JavaScript code in a separate file.

JavaScript-Syntax

ECMAScript's syntax draws heavily on the syntax of C and other C languages such as Java and Perl.

One, variable

1. Variables are defined by the var operator plus the variable name.

var age = 25;var mood = ' happy ';

2. Naming rules for variable names:

The first character must be a letter, an underscore (_), or a dollar sign ($);

Variable names cannot contain spaces or punctuation (except for underscores (_) and $), and variable names are case-sensitive;

You cannot use reserved words, keywords

To make the variable name more readable, you can insert an underscore in the variable name to separate it,

var my_mood = ' happy ';

3. Strict mode:

"Use Strict"

It is a compilation instruction

In strict mode, JavaScript execution results can vary greatly, supporting strict mode

Browser contains ie10+, firefox4+, opera12+, Chrome

Such as:

var aaa;   This is no problem AAA   //This will be an error in strict mode

Extended:

Since ECMAScript is loosely typed, there is a need for a means to detect the data type of a given variable---typeof

Six types: Undefined, Boolean, string, number, object, function.

Objects are: object, array, NULL, function

From a technical point of view, a function is an object, not a data type, but the function has some special properties, so it is necessary to differentiate functions and other objects through the typeof operator.

The question of rounding errors in floating-point numerical calculations is clear: this is a common problem with floating-point numbers based on IEEE754 numeric values, and other languages that use the same numeric format also exist .


Therefore, the use of decimal precision will appear deviation

Such as:

Results:

So when using the decimal point, if you want to get a certain value accurately, then this accuracy is a bug, people worry, so we

This can be done by converting the decimal point to an integer and then dividing by the number of digits divided by the converted integer when the operation is completed.

Such as:

Results:

This problem does not occur when you convert the decimal point back to an integer after the result can be seen.

JavaScript Basics 01

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.