Home > Web Front-end > JS Tutorial > body text

A very comprehensive collection of common JavaScript functions_javascript skills

WBOY
Release: 2016-05-16 15:18:44
Original
1234 people have browsed it

This article mainly summarizes the common functions of JavaScript, such as some commonly used JS objects, basic data structures, functional functions, etc., as well as some commonly used 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 interface
  • Implement local or remote storage.
  • Implement the front-end components of distributed network applications and perform data storage management in the background.
  • A complete distributed web application can be implemented using JavaScript.

1. Data types in JavaScript

JavaScript provides three metadata types, string, number, and Boolean. You can use typeof(v) to test the type of variable V, 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, dates and regular expressions are metadata types that can be encapsulated in other objects.

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

The variable value can be:

  • 1. Numeric value: such as string, number or Boolean value.
  • 2. Object reference: It can refer to typical objects, or it can be data, functions, dates or regular expressions.
  • 3. The special data value, Null, is a typical default value used to initialize objects.
  • 4. The special data undefined is often used for variables that have been defined but not assigned a value.

string is a series of Unicode strings, String such as "hello world", 'A3FO' or the empty string "". String concatenation can be performed through the + operator, or the = sign can be used to verify two characters Whether the strings are equal;

if (firstName + lastName === "James Bond") ...
Copy after login

numeric represents a 64-bit floating point number. There is no obvious distinction between integers and floating point numbers in JS. If the value of an expression is not equal to a certain number, then its value can be set to NaN, which means not a number and can be combined. isNaN is used.
The following table is detailed type testing and conversion

2. Variable scope
Currently, JavaScript and ES5 provide two scope types: global variables and function scope, and there is no block scope. The scope of block scope is unclear, so its use should be avoided. The following code, although it is a pattern commonly used by developers, is a trap.

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

All variable declarations are best placed at the beginning of the function. Block scope is supported in JS and ES6 versions, and variables are defined using the keyword let.

Strict Mode
Starting from ES5, strict mode is used to detect runtime errors. In strict mode, all variables must be declared. If an undeclared variable is assigned a value, an exception will be thrown.

Within a JavaScript file or

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template