Detailed introduction to JavaScript data types
1. Basic data types and reference data types
ECMAScript includes two different types of values: basic data types and reference data types.
Basic data types refer to simple data segments, and reference data types refer to objects composed of multiple values.
When we assign a variable to a variable, the first thing the parser has to confirm is whether the value is a basic type value or a reference type value.
2. Common basic data types:
Number, String, Boolean, Null and Undefined. Primitive data types are accessed by value, since the actual value held in the variable can be directly manipulated. Example:
var a = 10;
var b = a;
b = 20;
console.log(a); // 10 Value
Above, b obtains a copy of a's value. Although the values of the two variables are equal, the two variables store two different basic data type values.
b just saves a copy of a. Therefore, the change of b has no effect on a.
JS has defined a total of 6 data types for us, namely: undefined, null, boolean (Boolean), number (number), string (string), object (object). (Other data types are defined in ES6). Among them, the first 5 is a simple data type, and object is a complex data type
Before understanding each data type, let’s talk about variables, in any language Variables are containers for storing information. For example: in mathematics, x = 5; then x is the container of the number 5, and x is the variable. Use the var keyword to define a variable in JS. For example: var x = 5;
At this point, we have a good understanding of what a data type is. In mathematics, numbers are also divided into integers, decimals, and negative numbers. . . There are several types, and there are clear regulations on what algorithm is suitable for each type. So in the language of JS, these 6 data types are defined, as well as the usage rules and usage scenarios of each type. Next we will look at them one by one.
Before talking about each type, we first introduce a js operator: typeof (used to detect the data type of variables).
var a;
typeof(a); //undefined
var b = 123;
typeof b ; //number
It can be seen from the above code that typeof() is optional.
undefined
There is only one value which is undefined;
Then let’s define an undefined variable first:
var a = undefined;
We know that undefined means undefined, so what is the significance of this variable? In fact, undefined is not used to define a variable, but when the variable is not initialized, the value of undefined is automatically assigned. For example: var a;At this time, a is automatically assigned the value of undefined.
Then why do this? Let's think about mathematics. When we only write an x, can we say that this x is an integer, a decimal, or a negative number? Definitely not! In the same way, if there is no data type of undefined, we define a variable var a; can we say that this variable is a number? String? Or an object? Surely not? Now that we have undefined, we can say that this a is of type undefined. This is the meaning of undefined data type.
null
There is only one value which is null;
var b = null;
From a logical perspective, null represents a null pointer object. So what is the use of null? We can use typeof null; and find that the returned value is not null, but object, haha, you liar, didn’t you say that typeof can detect data types? In fact, this exactly illustrates the use of null. If we define a variable to prepare to save the object in the future. Then we'd better initialize this variable to null.
Another thing to mention here is: undefined is derived from the null value. So
undefined == null; //true
boolean
has two values, namely: true and false;
var c = true;
var d = false;
Although boolean The type only has two values, but all data types in js can be converted to and from boolean values. The conversion rules are as follows:
This type represents a number: var f = 1234566Data type
String Non -empty string empty string
# Number Non -0 digital values (including infinity) 0/nan
## Object any object null
. number
;
var g = 1.2356;
In addition, the number type has a special value: NaN (Not a Number)
This value Used to indicate a situation where an operand that is supposed to return a value does not return a value (so that an error is not thrown). For example, in other programming languages, dividing any numeric value by zero results in an error that stops code execution. But in JavaScript, any value divided by 0 will return NaN, so it will not affect the execution of other code.
stringvar s = "abcdef";Use this type to represent strings:
var t = "Beijing";
The string can be represented by single quotes (') or double quotes ("). As long as the variable is represented by single quotes Or expressed in double quotes, then this variable is the string . See the following examples:
var a = "true"; typeof a; //"string"var b = "5689"; typeof b; //"string"
##object##var o =new Object()An object is a collection of data and functions
.
;
o.name="beijing"; //Object propertiespropertyIsEnumerable(propertyName) - used to check whether the given property can be enumerated using the for-in statement. #toString() - Returns the string representation of the object. valueOf() - Returns the string, numerical or Boolean representation of the object.o.run = function(){}; //Object method
When you create an object, js will automatically add the following to the object instance Default properties and methods.
Constructor - holds the function used to create the current object. hasOwnProperty(propertyName) - is used to check that the given property is in the current object instance (not exists in the prototype of the instance. Among them, the property name (propertyName) as the parameter must be specified in the form of a string (for example: o.hasOwnProperty("name")) - Used to check whether the incoming object is the prototype of another object.
The above are the 6 basic data types of js. In the next article, let’s learn about the mutual conversion between these 6 data types.
The above is the detailed content of Detailed introduction to JavaScript data types. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

If you need to know how to use filtering with multiple criteria in Excel, the following tutorial will guide you through the steps to ensure you can filter and sort your data effectively. Excel's filtering function is very powerful and can help you extract the information you need from large amounts of data. This function can filter data according to the conditions you set and display only the parts that meet the conditions, making data management more efficient. By using the filter function, you can quickly find target data, saving time in finding and organizing data. This function can not only be applied to simple data lists, but can also be filtered based on multiple conditions to help you locate the information you need more accurately. Overall, Excel’s filtering function is a very practical

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

New SOTA for multimodal document understanding capabilities! Alibaba's mPLUG team released the latest open source work mPLUG-DocOwl1.5, which proposed a series of solutions to address the four major challenges of high-resolution image text recognition, general document structure understanding, instruction following, and introduction of external knowledge. Without further ado, let’s look at the effects first. One-click recognition and conversion of charts with complex structures into Markdown format: Charts of different styles are available: More detailed text recognition and positioning can also be easily handled: Detailed explanations of document understanding can also be given: You know, "Document Understanding" is currently An important scenario for the implementation of large language models. There are many products on the market to assist document reading. Some of them mainly use OCR systems for text recognition and cooperate with LLM for text processing.
