A brief analysis of JS original value and reference value issues

A brief analysis of JS original value and reference value issues

Primitive values ​​-> primitive types

Number String Boolean undefined null

Simple data segments stored on the stack, that is, their values ​​are stored directly at the location where the variable is accessed

Dynamic language -> scripting language -> interpreted language -> weakly typed language

Static language -> compiled language -> strongly typed language

null empty value initialization component function destruction function placeholder

Reference Value

object array function date RegExp

If a value is of a reference type, its storage is allocated from the heap. Since the size of the reference value will change, it cannot be placed on the stack, otherwise it will slow down the variable search. Instead, the value placed in the variable's stack space is the address where the object is stored on the heap. The address size is fixed, so storing it on the stack has no negative impact on the variable's performance.
ex

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>D1</title>
</head>
<body>
    <script type="text/javascript">
        var arr1 = [1,2,3,4];
        var arr2 = arr1;
        //arr1.push(5); //At this time, arr2 is printed as 1, 2, 3, 4, 5
        arr1 = [1,2]; //Reassigning value will not affect arr2
        document.write(arr2);
    </script>
</body>
</html>

This is the end of this article about JS original value and reference value. For more relevant JS original value and reference value content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed examples of storing primitive values ​​and reference values ​​in JS
  • JavaScript data manipulation - A brief discussion of the nature of primitive and reference value manipulation
  • JavaScript detects primitive values, reference values, and attributes

<<:  Introduction to vim plugin installation under Linux system

>>:  How to change the color of the entire row (tr) when the mouse stops in HTML

Recommend

22 Vue optimization tips (project practical)

Table of contents Code Optimization Using key in ...

Angular environment construction and simple experience summary

Introduction to Angular Angular is an open source...

Introduction to the use of select optgroup tag in html

Occasionally, I need to group select contents. In ...

Vue3+el-table realizes row and column conversion

Table of contents Row-Column Conversion Analyze t...

How to build a Vue3 desktop application

In this article, we will look at how to develop a...

Front-end vue+express file upload and download example

Create a new server.js yarn init -y yarn add expr...

Small details of web front-end development

1 The select tag must be closed <select><...

An in-depth introduction to React refs

1. What is Refs is called Resilient File System (...

Initial settings after installing Ubuntu 16 in the development environment

The office needs Ubuntu system as the Linux devel...

SMS verification code login function based on antd pro (process analysis)

Table of contents summary Overall process front e...

The difference between Input's size and maxlength attributes

I recently used the input size and maxlength attri...

JavaScript to achieve simple drag effect

This article shares the specific code of JavaScri...

Detailed explanation of HTML basics (Part 1)

1. Understand the WEB Web pages are mainly compos...

WeChat applet wxs date and time processing implementation example

Table of contents 1. Timestamp to date 2. Convert...