1.What is data? *Data is the ‘stuff’ that represents specific information stored in the memory. Its essence is 0101 binary. This article mainly shares with you the memory analysis of data variables in JavaScript, hoping to help everyone.
eg:18 //This 18 may only be age or score, etc.,
The data in the writing program must have a special meaning.
*Data has the basic characteristics of being readable and transferable (transferability is very important)
var a=2; b=a;//这个是传递a变量的数据的变量 a={2,4,5} b=a;//这个传递的是a对象的地址值
*Everything (everything) is data, and functions are also data
"Everything is Object" is an oxymoron because data can be divided into basic types and objects.
*The goal of all operations in the program: data
All businesses are additions, deletions, modifications, and searches of data. Operations include performing arithmetic operations on data, calling functions to pass parameters, assigning values, etc.
2. What is memory?
*The storage space (temporary) generated after the memory stick (circuit board) is powered on
Declaring a variable will automatically allocate memory
The memory that is released is the memory that can be reused (such as a Start setting the global variable. If you want to use this global variable later, you have to release it (that is, reassign a value to this variable))
*Generation and death: memory stick (integrated circuit board) == 》Power on==》Generate a certain amount of storage space==》Storage various data==》Power off==》All memory disappears
*The space of the memory is temporary, while the space of the hard disk is permanent
*A piece of memory contains 2 data
-->Data stored in memory (general data/address data)
-->Memory address value data
*Memory classification
->Stack (small space): global variables, local variables
->Heap( Larger space): Object
#3. What is a variable?
*The amount that the value can change is composed of variable name and variable value
*A variable corresponds to a small memory. The variable name (identification) is used to find the memory, and the variable value is the memory. Saved content
var a=3;
4. What is the relationship between memory, data and variables?
*Memory is a container, used to store data
*Variable (variable name) is the identifier of memory. Find the corresponding memory through variables, and then operate (read/write) the data in the memory
5. Issues with assignment and memory
Question: var a=XXX, what is stored in a memory What is it?
//了解内存只保存俩种值(基本类型值,对象地址值) var a=2;//a内存是基本类型的值:3 a={}//a内存是{}的地址值 var b=4; a=b;//a中保存的是:b保存的基本类型的值4 b=[]; a=b;//a中保存的是:b中的地址值
6. Regarding the issue of reference variable assignment
(1). Two reference variables point to the same object. One reference variable modifies the internal data, and the other Reference variables are also visible
*2个引用变量指向同一个对象,通过一个引用变量修改内部数据,另一个引用变量也看得见 var a1={n:3}; var a2=a1; a1.n=4; console.log(a2.n)//4 function fn (a) { a.n=8;//这是改变对象内部的数据,并没有改变对象 } fn(a1); console.log(a1.n,a2.n)//8 8//注意:当fn执行完时,a也就释放内存
(2). Two reference variables point to the same object, let one reference variable point to another object, and the other reference The variable still points to the original object
var b1={n:3}; var b2=b1; //b1={n:6};console.log(b2.n);//3 function fn1(a){a={n:9}}//a={n:9}这是创建了一个新的对象 fn1(b1); console.log(b1.n,b2.n);//3 3
7. When passing variable parameters when calling a function in js, is it passed by value or by reference?
* Only value is passed, no reference is passed, only the value of the variable is passed. It’s just that this value may be basic data, or it may be reference (address) data (object, function, array)
*If the latter is regarded as reference transfer, then both transfer and reference transfer can have
var a=3; function fn(a1){...} fn(a)//传递的是a的值(基本值)-----传递变量参数应该是值传递 a=function (){...} fn(a)//传递的是a的值(引用类型也就是地址值)--- //传递变量参数应该是值传递也可以说是引用传递
8. How does the js engine manage memory?
js engine is the code that parses and executes our js code
(1). Memory life cycle
a. Allocate the required memory
b. Use the allocated memory
. Release/return when not needed
(2).Release memory
*Stack space memory allocated for executing functions: automatically released after the function is executed
*Heap space memory for storing objects: when the memory is not referenced When pointed to, the object becomes a garbage object, and the garbage collector will later reclaim and release this memory
var a={}; console.log({})//空对象(有东西,只是没有我们定义的数据) a=null;//对象是在后面的某个时刻被垃圾回收器回收释放 function fn(){ var a=3; } fn()//函数执行完a立即释放
Related recommendations:
Detailed explanation of data interception issues in JavaScript
How to transfer data in JavaScript to PHP
Summary of data type conversion methods in JavaScript_Basic knowledge
The above is the detailed content of Memory analysis of data variables in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.