Five minutes to make your JavaScript even further!

As we know HTML (the backbone of web pages), CSS (style pages) and JS and old folk called the front iron, which is called the soul of JS front-end, which take you to find the bottom of the principles of JavaScript, I hope after reading this articles, you can have a deeper understanding of pairs JavaScript!

JS stands for JavaScript, belongs to a client is running in the browser-side scripting language. In fact, simply, JS is used to manipulate the DOM tree, change its structure or properties. In some of the results page the client can use JS to implement, does not require the server's response, if each switching labels need to interact with the server, the server load will be great. After performing some or page, you need to get the server to interact with the new data, then there is less variation on the page, if the interaction with the server rendering the entire page would be very slow, then the advantages of using JavaScript is very obvious the Therefore JS has become increasingly indispensable!

JS data in memory divided into two main categories heap, stack,

Stack: primitive data types (Undefined, Null, Boolean, Number, String)

Heap: reference data types (objects, arrays, and functions)

In some scenarios, we need the help of stack data structure to deal with some problems, so here we have to distinguish between these two data structures.

the difference:

Two different types of storage locations;

Simple data types are stored directly on the stack, occupies a small space, the definition of the main variables (memory address of a variable), Undefined, Null, Boolean, Number, String, for example, they are accessed by value. ;

Complex data types are stored on the heap objects occupy a large space, if the stack, the operating performance of the program memory; JavaScript is not directly access data in heap memory, so if we want to access complex data types, using the visit is a reference, in fact, complex data types stored in the stack pointer, the pointer to the type of address heap.

Memory Leak

Many people know, JS garbage collection mechanism, memory can matter, defines many variables in the global scope in the programming process, that JS will automatically recover, it is not true, these are no longer used in the memory is not released in time , it will have a memory leak.

About garbage collection: Quoted from "JavaScript The Definitive Guide (Fourth Edition)"

  Because of strings, objects and arrays there is no fixed size, the size of all when they are known, in order for them to dynamic storage allocation. JavaScript programs every time you create a string, an array or object, the interpreter must allocate memory to store that entity. As long as this dynamically allocated memory, this memory will eventually be released so that they can be reused, otherwise, JavaScript interpreter will completely consume all available system memory, causing the system to crash.

This passage explains why the system needs to garbage collection. JavaScript interpreter program to detect when an object is no longer used, and when he identified an object is useless when it put the memory occupied by the object released.

When local scope, if the function completes absence necessary variables, which is a JavaScript interpreter detects and judges, then recovered. But for global variables, not made to determine when not to, so we should reduce the use of global variables. Above: when is a summary of individual learning, if we can better follow, and follow-up of advanced learning aspect, there is a big help. Of course, their own way is the best way. One learns there will be confusion, lack of motivation. Here I recommend the front-end development Junyang: four hundred eighty-four 5, July Seven, seven hundred and sixty, which is the front end of the study, if you want to create web pages cool, want to learn programming. Himself compiled a front-end 2019 the most comprehensive study materials, from the most basic HTML + CSS + JS.

Guess you like

Origin blog.csdn.net/dj3235/article/details/91534121