Home Web Front-end JS Tutorial A brief introduction to js data types

A brief introduction to js data types

Sep 26, 2017 am 09:40 AM
javascript introduce Simple

The editor below will bring you a brief talk about the data types of js. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

When I was doing some projects recently, I found that my js foundation was still not solid enough. I read the Rhino book again to deepen my understanding and impression. So starting from this article, the rest is about native js.

In this article, we will introduce one of the data types of js in detail.

1. The data types of javaScript (hereinafter referred to as js) are divided into two categories: Primitive types and object types. The primitive types of js include numbers, strings and Boolean values.

2. js has two special primitive values: null (empty) and undefined (undefined), they are not numbers, strings and Boolean values. They usually each represent a unique member of their special type.

3. In js, in addition to numbers, strings, Boolean values, null and undefined, there are objects. Objects are a collection of attributes. Each attribute They are all composed of "name/value pairs" (the value can be a primitive value, such as a number, a string, or an object).

4. Ordinary js objects are unordered collections of "named values". js also defines a special object - array (array), represents an ordered collection of numbered values. js specifically defines syntax for arrays, which we will explain in detail later. Make arrays have some unique behavioral characteristics that are different from ordinary objects.

5. JS also defines a special object - function. A function has an object with executable code associated with it. The executable code is run by calling the function and the results of the operation are returned. Like arrays, functions behave differently from other objects.

6. If the function is used to initialize (using the new operator) a newly created object, we call it a constructor function. Each constructor defines a class object

Let me explain the first type of data type to you in detail - Number

According to the number format in js, the range of integers that can be represented is from -9007199254740992~9007199254740992 (that is, -253~253) contains boundary values.

In js, when a number appears directly in the js program, we call it a digital direct quantity. js supports digital direct quantities in multiple formats.

Integer literal, using a sequence of numbers to represent a decimal integer, such as: 0 3 133333

Floating-point literal, floating-point literal can contain a decimal point, such as: 3.14. 3333 2.02e23(2.02x1023)e or E represents how many powers

The arithmetic operations in js (+(addition), -(subtraction), x(multiplication), /(division), %(remainder )) In addition to these basic operators, js also supports more complex arithmetic operations, which are implemented through functions and constants defined as properties of the Math object:


Math.pow(2,53)       //2的53次幂也就是8007199254740992
  Math.round(.6)       //1.0  四舍五入
  Math.ceil(.6)        //1.0   向上取整
  Math.floor(.6)       //0.0   向下取整
  Math.abs(-5)        //5    求绝对值
  Math.max(x,y.z)       //返回最大值
  Math.min(x,y.z)       //返回最小值
  Math.random()       //生成一个大于等于0小于1的伪随机数
  Math.PI           //π  圆周率
  Math.E           //e  自然对数的底数
  Math.sqrt(3)        //3的平方根
  Math.pow(3,1/3)        //3的立方根
  Math.sin(0)           //三角函数:还有cos()和atan等
Copy after login

js uses IEEE-754 floating point number representation, which is a binary representation that can accurately represent fractions, such as 1/2, 1/8 and 1/1024, but the fractions we commonly use are decimal. The fractions are 1/10/1/100 etc. Binary floating point number representation cannot accurately represent a simple number like 0.1.

For example


0.3-0.2是不等于0.2-0.1的,在真实的运行环境下
0.3-0.2=0.09999999999999998   而
0.2-0.1=0.1
这是由于舍入误差导致的
Copy after login

The content of numeric types is probably finished. In the next chapter, I will tell you about the second data type- characters. string

The above is the detailed content of A brief introduction to js data types. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

The easiest way to query the hard drive serial number The easiest way to query the hard drive serial number Feb 26, 2024 pm 02:24 PM

The hard disk serial number is an important identifier of the hard disk and is usually used to uniquely identify the hard disk and identify the hardware. In some cases, we may need to query the hard drive serial number, such as when installing an operating system, finding the correct device driver, or performing hard drive repairs. This article will introduce some simple methods to help you check the hard drive serial number. Method 1: Use Windows Command Prompt to open the command prompt. In Windows system, press Win+R keys, enter "cmd" and press Enter key to open the command

Detailed introduction to what wapi is Detailed introduction to what wapi is Jan 07, 2024 pm 09:14 PM

Users may have seen the term wapi when using the Internet, but for some people they definitely don’t know what wapi is. The following is a detailed introduction to help those who don’t know to understand. What is wapi: Answer: wapi is the infrastructure for wireless LAN authentication and confidentiality. This is like functions such as infrared and Bluetooth, which are generally covered near places such as office buildings. Basically they are owned by a small department, so the scope of this function is only a few kilometers. Related introduction to wapi: 1. Wapi is a transmission protocol in wireless LAN. 2. This technology can avoid the problems of narrow-band communication and enable better communication. 3. Only one code is needed to transmit the signal

Detailed explanation of whether win11 can run PUBG game Detailed explanation of whether win11 can run PUBG game Jan 06, 2024 pm 07:17 PM

Pubg, also known as PlayerUnknown's Battlegrounds, is a very classic shooting battle royale game that has attracted a lot of players since its popularity in 2016. After the recent launch of win11 system, many players want to play it on win11. Let's follow the editor to see if win11 can play pubg. Can win11 play pubg? Answer: Win11 can play pubg. 1. At the beginning of win11, because win11 needed to enable tpm, many players were banned from pubg. 2. However, based on player feedback, Blue Hole has solved this problem, and now you can play pubg normally in win11. 3. If you meet a pub

Detailed introduction to whether i5 processor can install win11 Detailed introduction to whether i5 processor can install win11 Dec 27, 2023 pm 05:03 PM

i5 is a series of processors owned by Intel. It has various versions of the 11th generation i5, and each generation has different performance. Therefore, whether the i5 processor can install win11 depends on which generation of the processor it is. Let’s follow the editor to learn about it separately. Can i5 processor be installed with win11: Answer: i5 processor can be installed with win11. 1. The eighth-generation and subsequent i51, eighth-generation and subsequent i5 processors can meet Microsoft’s minimum configuration requirements. 2. Therefore, we only need to enter the Microsoft website and download a "Win11 Installation Assistant" 3. After the download is completed, run the installation assistant and follow the prompts to install Win11. 2. i51 before the eighth generation and after the eighth generation

Introducing the latest Win 11 sound tuning method Introducing the latest Win 11 sound tuning method Jan 08, 2024 pm 06:41 PM

After updating to the latest win11, many users find that the sound of their system has changed slightly, but they don’t know how to adjust it. So today, this site brings you an introduction to the latest win11 sound adjustment method for your computer. It is not difficult to operate. And the choices are diverse, come and download and try them out. How to adjust the sound of the latest computer system Windows 11 1. First, right-click the sound icon in the lower right corner of the desktop and select "Playback Settings". 2. Then enter settings and click "Speaker" in the playback bar. 3. Then click "Properties" on the lower right. 4. Click the "Enhance" option bar in the properties. 5. At this time, if the √ in front of "Disable all sound effects" is checked, cancel it. 6. After that, you can select the sound effects below to set and click

PyCharm Beginner's Guide: Comprehensive Analysis of Replacement Functions PyCharm Beginner's Guide: Comprehensive Analysis of Replacement Functions Feb 25, 2024 am 11:15 AM

PyCharm is a powerful Python integrated development environment with rich functions and tools that can greatly improve development efficiency. Among them, the replacement function is one of the functions frequently used in the development process, which can help developers quickly modify the code and improve the code quality. This article will introduce PyCharm's replacement function in detail, combined with specific code examples, to help novices better master and use this function. Introduction to the replacement function PyCharm's replacement function can help developers quickly replace specified text in the code

Detailed information on the location of the printer driver on your computer Detailed information on the location of the printer driver on your computer Jan 08, 2024 pm 03:29 PM

Many users have printer drivers installed on their computers but don't know how to find them. Therefore, today I bring you a detailed introduction to the location of the printer driver in the computer. For those who don’t know yet, let’s take a look at where to find the printer driver. When rewriting content without changing the original meaning, you need to The language is rewritten to Chinese, and the original sentence does not need to appear. First, it is recommended to use third-party software to search. 2. Find "Toolbox" in the upper right corner. 3. Find and click "Device Manager" below. Rewritten sentence: 3. Find and click "Device Manager" at the bottom 4. Then open "Print Queue" and find your printer device. This time it is your printer name and model. 5. Right-click the printer device and you can update or uninstall it.

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

See all articles