Table of Contents
Reply content:
Home Backend Development PHP Tutorial What are the differences in how these two types of object literals (json) are operated in JavaScript?

What are the differences in how these two types of object literals (json) are operated in JavaScript?

Jul 06, 2016 pm 01:53 PM
c++ java javascript json php

1. Does object literal === json type object?
2. Suppose there is a json type object, such as var a={};
3. What is the difference between operating json in the following ways:
①a.propertyA=valueA;
②var a={propertyA :valueA};

It is a way of defining attributes internally and externally

Reply content:

1. Does object literal === json type object?
2. Suppose there is a json type object, such as var a={};
3. What is the difference between operating json in the following ways:
①a.propertyA=valueA;
②var a={propertyA :valueA};

It is a way of defining attributes internally and externally

1. The object is a reference type, the === method is not true;

2. There is no difference between a.propertA=valueA and a={propertyA:valueA};. But please note that there is a difference if it is var a=function(){};a.prototype.propertyA=valueA and a.prototype={propertyA:valueA}.

  1. There is no such thing as a JSON type object. var obj = {}; is called an object literal. JSON is the same syntax format as XML.

  2. a={propertyA:valueA}; is to directly assign a value to a literal. a.propertyA=valueA or a[propertyA]=valueA can be used to access/modify/increase the attribute value of a literal. (When using the dot operator, propertyA must be a legal JavaScript identifier) ​​

1. Object literal refers to using key/value to define objects. It is simple and clear. There is no limit on the value. The value of json can only be: numbers (integers or floating point numbers), strings (in (in double quotes), logical value (true or false), array (in square brackets), object (in curly brackets), null. In other words, the value of json cannot be a function. So there is a difference between the two.
2, a.propertyA = valueA; is equivalent to adding an attribute to the object, and the previously defined attributes still exist. And a = {propertyA: valueA}; overwrites a, that is, the attributes in the previous a have been overwritten. The a object only has the attribute propertyA.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1258
29
C# Tutorial
1232
24
The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

C  : Is It Dying or Simply Evolving? C : Is It Dying or Simply Evolving? Apr 24, 2025 am 12:13 AM

C isnotdying;it'sevolving.1)C remainsrelevantduetoitsversatilityandefficiencyinperformance-criticalapplications.2)Thelanguageiscontinuouslyupdated,withC 20introducingfeatureslikemodulesandcoroutinestoimproveusabilityandperformance.3)Despitechallen

The Future of C  : Adaptations and Innovations The Future of C : Adaptations and Innovations Apr 27, 2025 am 12:25 AM

The future of C will focus on parallel computing, security, modularization and AI/machine learning: 1) Parallel computing will be enhanced through features such as coroutines; 2) Security will be improved through stricter type checking and memory management mechanisms; 3) Modulation will simplify code organization and compilation; 4) AI and machine learning will prompt C to adapt to new needs, such as numerical computing and GPU programming support.

What does 'platform independence' mean in the context of Java? What does 'platform independence' mean in the context of Java? Apr 23, 2025 am 12:05 AM

Java's platform independence means that the code written can run on any platform with JVM installed without modification. 1) Java source code is compiled into bytecode, 2) Bytecode is interpreted and executed by the JVM, 3) The JVM provides memory management and garbage collection functions to ensure that the program runs on different operating systems.

C   and JavaScript: The Connection Explained C and JavaScript: The Connection Explained Apr 23, 2025 am 12:07 AM

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

C   in the Modern World: Applications and Industries C in the Modern World: Applications and Industries Apr 23, 2025 am 12:10 AM

C is widely used and important in the modern world. 1) In game development, C is widely used for its high performance and polymorphism, such as UnrealEngine and Unity. 2) In financial trading systems, C's low latency and high throughput make it the first choice, suitable for high-frequency trading and real-time data analysis.

Discuss situations where writing platform-specific code in Java might be necessary. Discuss situations where writing platform-specific code in Java might be necessary. Apr 25, 2025 am 12:22 AM

Reasons for writing platform-specific code in Java include access to specific operating system features, interacting with specific hardware, and optimizing performance. 1) Use JNA or JNI to access the Windows registry; 2) Interact with Linux-specific hardware drivers through JNI; 3) Use Metal to optimize gaming performance on macOS through JNI. Nevertheless, writing platform-specific code can affect the portability of the code, increase complexity, and potentially pose performance overhead and security risks.

What happens if session_start() is called multiple times? What happens if session_start() is called multiple times? Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

See all articles