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

Set IE8 to use IE7 style code

<meta http-equiv="x-ua-compatible" co...

How to use Vue+ElementUI Tree

The use of Vue+ElementUI Tree is for your referen...

MySQL 5.6 root password modification tutorial

1. After installing MySQL 5.6, it cannot be enabl...

Basic syntax of MySQL index

An index is a sorted data structure! The fields t...

How to install and modify the initial password of mysql5.7.18

For Centos installation of MySQL, please refer to...

DOCTYPE type detailed introduction

<br />We usually declare DOCTYPE in HTML in ...

A brief analysis of the use of watchEffect in Vue3

Preface Everyone should be familiar with the watc...

A brief discussion on the correct approach to MySQL table space recovery

Table of contents Preliminary Notes Problem Repro...

Implementation of Docker deployment of ElasticSearch and ElasticSearch-Head

This article mainly explains how to deploy Elasti...

js implements the algorithm for specifying the order and amount of red envelopes

This article shares the specific code of js to im...

HTML Basics: The basic structure of HTML

The basic structure of HTML hypertext documents is...

HTML discount price calculation implementation principle and script code

Copy code The code is as follows: <!DOCTYPE HT...

jQuery plugin to implement stacked menu

A jQuery plugin every day - stacked menu, for you...