Some special knowledge of JavaScript

Source: Internet
Author: User

Basic knowledge

1. Comment/**/block comment, conflict with regular expression, unsafe.

2.js numeric type has only one, which is a 64-bit floating value

3.NaN is a numeric value, and he cannot produce the result of a normal result. Nan is not equal to any value, including its own. isNaN detect if Nan

All characters in 4.Js are 16 bits.

5. Declaration of functions and definition of functions:

function declaration

Console.log (f);
function f (x) {
return x;

function definition
Console.log (z);//undefined
var z = function (x) {
return x;

The difference: The function definition, just the variable declaration ahead of time, the initialization code of the variable is still in its original position. function declaration: Both the function name and the function body are in advance, and all functions and functions nested within the script are declared before the other code. (variable promotion, z is what variable will be promoted, here just to illustrate the difference between function declaration and definition)


var a = [1,,,, 5];//other three values are undefined sparse array

var b = [1,2,3,4];

var c = [5,6];

1.concat ()

B.concat (c);//[1,2,3,4,5,6]


C.join ();//5,6

C.join ("");//56

C.join ("-");//5-6

3.reverse (); reverse

4.splice ()//delete and insert

1) Delete

B.splice;//1 for deleting several from the beginning of the first 2

2) Insert

B.splice (1,2,33,44,44,22);//1 is a number from the beginning of the first, 2 for the deletion of a few, 2 after the numeric value is inserted.

5. Some of the loops, the same parameters, the function is different. The return value is also not possible.

1) Every return value: Boolean

B.every (function (v, I, arr) {

V Self-value, I-index, arr array


2) foreach, map, some, filter

6.slice () Select Slice (start,end)//Include start excluding end


AddEventListener (A, B, c)//a functions called for event names such as Click,b, C is the capture handler

This method registers multiple handler functions of the same event type for an object

varBTN = document.getElementById ('btn'); Btn.addeventlistener ('Click', function () {alert ('a'); ); Btn.addeventlistener ('Click', function () {alert ('b');} ); Btn.onclick=function () {alert ('cc');};
Btn.onclick=function () {alert ('DD');};

Alert ("CC") is not executed here;

Some special knowledge of JavaScript

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: 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.