In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to solve the problem of js data type and reference type, as well as deep and shallow copy and memory allocation. I think it is very practical, so I share it with you. I hope you can get something after reading this article.
Deep and shallow copy of js
Shallow copy generally refers to the basic type of replication.
Deep copy generally refers to the copy of the reference type, which also copies the value of the reference type.
Give an example
The sessionStorage of H6 can only store strings, so when you want to store json, you have to convert json to string using JSON.stringify (), and then convert json to json data using JSON.parse ().
Disadvantages: JSON.parse and JSON.stringify only support more than IE9+
To solve this problem, the depth ratio copy method can be used.
Memory allocation problems (heap and stack) in js
Basic type types in js are generally stored in the stack. These types occupy a fixed amount of space in memory, and their values are stored in the stack space, which we access by value.
Reference types are data of variable size, but their address size is fixed, so the address is stored in the stack and the value is stored in the heap.
1. Stack memory: store basic types. Heap memory: stores the reference type (stores a primitive type value in the stack memory to save the address of the object in the heap memory to reference the object. )
2. The basic type is destroyed at the end of the current execution environment, while the reference type is not destroyed with the end of the execution environment, and the object is reclaimed by the garbage collection mechanism only when all the variables that reference it do not exist.
Js basic data types and reference types
Basic data types include number boolean string undefined null symbol
Reference data type: array obj function
The above is how to solve the problems of js data type and reference type, as well as deep and shallow copy and memory allocation. I believe that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.