Learn more about data types in JavaScript
The data types of JavaScript are divided into two types, one is the basic data type and the other is the reference data type
1. Basic data types include:
Number - - (number)
String - - (string)
Boolean - - (Boolean value)
Undefined - - (Undefined)
- ##Null - - (Empty)
- Symbol - - (Symbol)
The following all belong to Object:2.Array - - (array)
3.Function - - (function)
4.Date - - (time)
5.RegExp - - (regular)
6...(and many more)
Values of basic data types:
Number:
Numbers (numbers can be with or without a decimal point), NaN, InfinityString:
String Can be any text within quotes. Both double quotes and single quotes are OK. You can also use the ES6 template string ``, such as:
var a = 'xxx';var a = "xxx";
Boolean:
There are only two values: true or false. Boolean values are commonly used in conditional testing. For example, to determine whether 1>2 is correct, return true if it is correct, and return false if it is incorrect. Then we can perform two different operations based on the returned results.Undefined:
Take a value of undefined. means the variable does not contain any value. is an undefined state.Null:
indicates that the value of the variable is empty, and the variable can be cleared by setting the value of the variable to null.Symbol:
For a detailed introduction to Symbol, please go to the detailed introduction of ES6 Ruan Yifeng symbolsIntroduction to reference data types :
Array:
Array: Save a set of data
The function of the array object is : Use separate variable names to store a series of values.
(Dynamic array: the length can be automatically called based on the number of elements)Concept:
1), Element: the data saved in the array space 2), length: the number of elements saved in the array
3), subscript (index): the number of the elements in the array, starting from 0 and ending with (length of the array - 1)
Usage:
var arr = [];//直接量 var arr = new Array();//创建数组对象。 var arr = [1,2,3];//直接量,在创建数组对象的同时初始化保存的数据。 var arr = new Array(1,2,3);在创建数组对象的同时初始化保存的数据。 var arr = new Array(size);//size为数字参数,表示创建数组时先预定size个空间。
数组名[下标]
- Ordinary loop
for(let i = 0;i < array.length; i++) { //array[i]}
- for-in
for(let 变量名 in 数组名) { //变量名中所保存的值是数组下标编号的字符串内容 //仍然使用“数组名[字符串下标]”来访问数组对应下标处的元素}
- for-of( ES6)
for(let 变量名 of 数组名) { //变量名中所保存的值是数组中当前便利到的元素值}
- Array api
- For a detailed introduction to the array API, please see the common methods of the array
Object:
(OOP: Everything is an object) The methods to create objects are: 1. Direct quantity:var stu = { name: '李四', age: 18, eat: function(pig) { console.log('吃:' + pig) }}
function Person() { this.name = 'jack'; this.job = function() { alert('program'); }}var person = new Person();
var person = new Object();person.name = 'jack';person.sex = 'girl';
through object method. Attribute call of object:
Object name.Attribute nameObject name.Method name ([Parameter list])Or: Object name["Attribute name"]Object name["Method name" 】();Function:
A function is an event-driven or reusable block of code when it is called. Essence: code block. Definition: 1), declaration functionfunction 函数名(参数列表) { //函数主体:可被重复使用的代码块}
var 变量名 = function(参数列表) { //函数主体:可被重复使用的代码块}
函数名()
document.getElementById(‘xx’).onclick = 函数名;
- Formal parameters (formal parameters): parameters when the function is defined
- Actual parameters (actual parameters): parameters when the function is called
return 表达式;
Basic data type The difference from reference data types:
The values of basic data types are stored on the stack. Values of reference data types are stored in the heap. For more programming-related knowledge, please visit:Programming Teaching! !
The above is the detailed content of Learn more about data types in JavaScript. 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

AI Hentai Generator
Generate AI Hentai for free.

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



In a MySQL database, gender fields can usually be stored using the ENUM type. ENUM is an enumeration type that allows us to select one as the value of a field from a set of predefined values. ENUM is a good choice when representing a fixed and limited option like gender. Let's look at a specific code example: Suppose we have a table called "users" that contains user information, including gender. Now we want to create a field for gender, we can design the table structure like this: CRE

In MySQL, the most suitable data type for gender fields is the ENUM enumeration type. The ENUM enumeration type is a data type that allows the definition of a set of possible values. The gender field is suitable for using the ENUM type because gender usually only has two values, namely male and female. Next, I will use specific code examples to show how to create a gender field in MySQL and use the ENUM enumeration type to store gender information. The following are the steps: First, create a table named users in MySQL, including

Python is widely used in a wide range of fields with its simple and easy-to-read syntax. It is crucial to master the basic structure of Python syntax, both to improve programming efficiency and to gain a deep understanding of how the code works. To this end, this article provides a comprehensive mind map detailing various aspects of Python syntax. Variables and Data Types Variables are containers used to store data in Python. The mind map shows common Python data types, including integers, floating point numbers, strings, Boolean values, and lists. Each data type has its own characteristics and operation methods. Operators Operators are used to perform various operations on data types. The mind map covers the different operator types in Python, such as arithmetic operators, ratio

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

When designing database tables, choosing the appropriate data type is very important for performance optimization and data storage efficiency. In the MySQL database, there is really no so-called best choice for the data type to store the gender field, because the gender field generally only has two values: male or female. But for efficiency and space saving, we can choose a suitable data type to store the gender field. In MySQL, the most commonly used data type to store gender fields is the enumeration type. An enumeration type is a data type that can limit the value of a field to a limited set.

Detailed explanation of how to use Boolean types in MySQL MySQL is a commonly used relational database management system. In practical applications, it is often necessary to use Boolean types to represent logical true and false values. There are two representation methods of Boolean type in MySQL: TINYINT(1) and BOOL. This article will introduce in detail the use of Boolean types in MySQL, including the definition, assignment, query and modification of Boolean types, and explain it with specific code examples. 1. The Boolean type is defined in MySQL and can be

C language is a widely used computer programming language that is efficient, flexible and powerful. To be proficient in programming in C language, you first need to understand its basic syntax and data types. This article will introduce the basic syntax and data types of C language and give examples. 1. Basic syntax 1.1 Comments In C language, comments can be used to explain the code to facilitate understanding and maintenance. Comments can be divided into single-line comments and multi-line comments. //This is a single-line comment/*This is a multi-line comment*/1.2 Keyword C language

1. Introduction to Python Python is a general-purpose programming language that is easy to learn and powerful. It was created by Guido van Rossum in 1991. Python's design philosophy emphasizes code readability and provides developers with rich libraries and tools to help them build various applications quickly and efficiently. 2. Python basic syntax The basic syntax of Python is similar to other programming languages, including variables, data types, operators, control flow statements, etc. Variables are used to store data. Data types define the data types that variables can store. Operators are used to perform various operations on data. Control flow statements are used to control the execution flow of the program. 3.Python data types in Python
