当前位置:网站首页>JS data types and mutual conversion
JS data types and mutual conversion
2022-07-25 11:47:00 【c_ perfectworld】
data type
In the computer , Different data requires different space , In order to facilitate the division of data into data of different sizes , Make the most of storage space , So different data types are defined
JS Is a weakly typed or dynamic language , This means that the type of the variable is not declared in advance , While the program is running , The type will be automatically determined
The data type of a variable is defined by JS engine according to = The data type of the variable value on the right is used to judge Of , After running , Variables determine the data type
JS Have dynamic types , It also means that the same variable can be used as a different type
Classification of data types
- Simple data type (Number、String、Boolean、Undefined、Null)
- Complex data type (object)

Digital Number
JS Numeric types can be used to hold integer values , You can also save decimals ( Floating point numbers )
1. Digital base system
The most common system is binary 、 octal 、 Decimal system 、 Hexadecimal
octal : Numbers Add in front 0 For octal , Every eight enters one.
Hexadecimal :0~9 a~f Numbers Add in front 0x For hexadecimal
2. Digital range
js The maximum and minimum of the values in

3. Three special values of digital type

- infinity For infinity , Greater than any number
- -infinity For infinitesimal , Less than any number
- NaN,Not a number Represents a non numerical value
isNaN() Used to judge non numbers , And return a value , If it is a number, it returns false, If it's not a number, return true
String type String
String type can be any text in quotation marks , Its grammar is “ Double quotes ” and ‘ Single quotation marks ’ Single quotation marks are recommended
1. String quotes nested
JS Can be used in the Single quotes nested double quotes , Or use Double quotes nested single quotes ( Double outside and single inside , Single outside and double inside )
2. String escape character
similar HTML The special characters in it , There are also special characters in strings , We call it the escape character
All the escape characters are \ At the beginning , The common escape characters and their descriptions are as follows :

3. String length

Use length To detect the length of the string
4. String splicing
- Multiple strings can be used + Splicing , The splicing method is character string + Any kind of = The new string after splicing
- Any type added to the string will be converted into a string before splicing , And then splice it into a new string
+ To sum up the pithy formula : Add the values , The characters are connected
5. String concatenation strengthens
var str = ` I this year ${age} Year old `
Don't write variables into strings , It is realized by connecting with a string
A formula for connecting variables to strings : Lead and add Cut out the numbers , Variable plus middle
- We will splice strings and variables , Because variables can easily modify the values inside
- Variables cannot be quoted , Because quoted variables become strings
Boolean type Boolean
The boolean type has two values :true and false, among true Said really ,false Said the false
Undefined and Null
A variable that has not been assigned a value after declaration will have a default trace undefined( Data type not defined )
undefined Add it to the number and the result is NaN
Null ( Null value )
Symbol(ES6)
var test = Symbol(‘123’);
Get the data type of the test variable
typeof + Spaces can be used to detect the data type of variables
Literal
Is a representation of a fixed value , A literal quantity is how to express this value
- Number literal quantity :8,9,10
- Literal of a string :‘ Black horse programmer ’
- Boolean literal :true,false
Conversion of data types
hold A variable of one data type is converted to another data type
Convert to string

Variable .toString() console.log(String( Variable )) console.log( Variable +")
- toString() and String() It's not the same way
- Plus sign splicing conversion is also called implicit conversion
Convert to digital

- parseInt and parseFloat The case of words
Convert to Boolean

- representative Empty , no The value of will be converted to false, Such as :0 NaN、null、undefined
- The rest of the values are converted to true
Interpreted and compiled languages
A tool for translating programming languages into machine languages , It's called a translator
- There are two ways of translator translation : One is compile , The other is explain , The difference lies in The time point of translation is different
- The compiler is in Compile before code execution , Generate intermediate code file
- The interpreter is in Compile at runtime , And execute immediately
identifier
Developers are variables 、 attribute 、 function 、 The name of the parameter
Identifier cannot be keyword and Reserved words
keyword
JS Words that have already been used , They can no longer be used as variable names , Method name

Reserved words
Reserved keywords

边栏推荐
- Similarity matrix, diagonalization condition
- Onenet platform control w5500 development board LED light
- SQL注入 Less18(头部注入+报错注入)
- 动态规划问题03_最大子段和
- 【mysql学习08】
- Make a reliable delay queue with redis
- Teach you how to configure S2E as the working mode of TCP server through MCU
- 动态规划问题05_导弹拦截
- W5500 adjusts the brightness of LED light band through upper computer control
- JS运算符
猜你喜欢

黑客入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。

【leetcode刷题】

基于MATLAB的常见线性调制方法

Wiznet embedded Ethernet technology training open class (free!!!)

【IMX6ULL笔记】--内核底层驱动初步探究

My colleague looked at my code and exclaimed: how can I use a singleton in unity

The most efficient note taking method in the world (change your old version of note taking method)

ArcMap cannot start the solution

谣言检测文献阅读十一—Preventing rumor spread with deep learning

Chapter 4 linear equations
随机推荐
【mysql学习09】
活动报名 | 玩转 Kubernetes 容器服务提高班正式开营!
[recursion] 938. Range and of binary search tree
基于MATLAB的常见线性调制方法
Learn NLP with Transformer (Chapter 1)
硬件外设=maixpy3
Varest blueprint settings JSON
MIIdock简述
JDBC summary
How to solve the problem that "w5500 chip cannot connect to the server immediately after power failure and restart in tcp_client mode"
黑客入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。
Leetcode sword finger offer 28. symmetric binary tree
相似矩阵,可对角化条件
Use three.js to realize the cool cyberpunk style 3D digital earth large screen
SQL注入 Less23(过滤注释符)
贪心问题01_活动安排问题
[MySQL learning 08]
工作面试总遇秒杀?看了京东T8大咖私藏的秒杀系统笔记,已献出膝盖
JS作用域以及预解析
什么是全局事件总线?