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

JavaScript to implement dynamic digital clock

This article shares the specific code for impleme...

12 Javascript table controls (DataGrid) are sorted out

When the DataSource property of a DataGrid control...

Detailed explanation of the function and usage of DOCTYPE declaration

1. Browser rendering mode and doctype Some web pa...

Detailed explanation of the solution for migrating antd+react projects to vite

Antd+react+webpack is often the standard combinat...

JavaScript to implement a simple clock

This article example shares the specific code for...

Example code for converting Mysql query result set into JSON data

Mysql converts query result set into JSON data Pr...

How to view image information in Docker

In this article, we will need to learn how to vie...

MYSQL local installation and problem solving

Preface This article is quite detailed and even a...

The best way to start a jar package project under Centos7 server

Preface Everyone knows how to run a jar package o...

MySQL view introduction and basic operation tutorial

Preface View is a very useful database object in ...

Comprehensive inventory of important log files in MySQL

Table of contents Introduction Log classification...

Analysis of the process of building a cluster environment with Apache and Tomcat

In fact, it is not difficult to build an Apache c...

Several methods of implementing carousel images in JS

Carousel The main idea is: In the large container...