Comprehensive collection of common JavaScript Functions _ javascript skills

Source: Internet
Author: User
This article mainly shares a comprehensive collection of common JavaScript Functions, some common JavaScript objects, basic data structures, function functions, etc, interested friends can refer to this article to summarize common JavaScript Functions, such as common JavaScript objects, basic data structures, function functions, and some common design patterns.

Directory:

As we all know, JavaScript is a dynamic object-oriented programming language that can achieve the following effects:

  • Rich Web page Functions
  • Rich Web interfaces
  • Local or remote storage.
  • Implements front-end components of distributed network applications and manages data storage in the background.
  • JavaScript can be used to implement a complete distributed Web application.

I. Data Types in JavaScript

JavaScript provides three types of metadata,String, number, and Boolean, You can use typeof (v) to test the variable V type, typeof (v) = "number"

Provides five basic reference types:Object, Array, Function, Date and RegExp. Arrays, functions, dates, and regular expressions are special types, but strictly speaking, date and regular expressions are metadata types and can be encapsulated in other objects.

In JS, the variable type, array element type, function parameters, and return value types do not need to be declared. conversions between types are automatically executed.

The variable value can be:

  • 1. Value: such as a string, number, or Boolean value.
  • 2. Object Reference: a typical object, Data, function, date, or regular expression can be referenced.
  • 3. Special data value, Null, is a typical default value for object initialization.
  • 4. Special Data undefined, often used for variables that have been defined but are not assigned a value.

String is a series of Unicode strings, such as "hello world", "A3FO", or an empty String "". string connections can be executed using the + operator, you can also use "=" to verify whether two strings are equal;

if (firstName + lastName === "James Bond") ...

Numeric indicates a 64-bit floating point number. In JS, there is no obvious distinction between integer and floating point number. If the value of an expression is not equal to a number, its value can be set to NaN, indicating that it is not a number, it can be used together with isNaN.
The following table shows detailed type tests and conversions.

II. Scope of Variables
Currently, JavaScript and ES5 provide two types of scopes: global variables and function scopes without block scopes. The range of block scopes is not clear, so use of block Scopes should be avoided. The following code, despite being a common Pattern by developers, is a trap.

function foo() { for (var i=0; i < 10; i++) { ... // do something with i }}

It is best to declare all variables at the beginning of the function. In JS and ES6 versions, block scopes are supported and variables are defined using the keyword "let.

Strict Mode)
Starting from ES5, the strict mode is used to detect running errors. In the strict mode, all variables must be declared. If you assign a value to an undeclared variable, an exception is thrown.

In a JavaScript file or

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.