当前位置:网站首页>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

边栏推荐
- Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.
- [tree] 100. Same tree
- 任何时间,任何地点,超级侦探,认真办案!
- Oracle parsing XML with the same name
- JVM性能调优方法
- W5500 upload temperature and humidity to onenet platform
- How to judge the performance of static code quality analysis tools? These five factors must be considered
- 基于W5500实现的考勤系统
- 世界上最高效的笔记方法(改变你那老版的记笔记方法吧)
- Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
猜你喜欢

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

基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现

The most efficient note taking method in the world (change your old version of note taking method)
![[MySQL learning 09]](/img/27/2578f320789ed32552d6f69f14a151.png)
[MySQL learning 09]

教你如何通过MCU将S2E配置为UDP的工作模式

Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network

如何解决“W5500芯片在TCP_Client模式下,断电重启之后无法立即连接到服务器”的问题

OneNET平台控制W5500开发板LED灯

Similarity matrix, diagonalization condition
![[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training](/img/c8/fe18308ddad5cb2fbccb79d2d8a2b6.png)
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training
随机推荐
教你如何通过MCU配置S2E为TCP Client的工作模式
Esp8266 uses drv8833 drive board to drive N20 motor
Understanding: idea uses Scala to write wordcount programs and generate jar packages
Shell - Chapter 8 exercise
Oracle parsing XML with the same name
软件缺陷的管理
Filter过滤器解决request请求参数乱码的原理解析
布局管理==PYQT5
大话DevOps监控,团队如何选择监控工具?
矩阵的特征值和特征向量
信号与槽机制==PYQT5
leetcode 剑指 Offer 27. 二叉树的镜像
什么是全局事件总线?
Chapter 4 linear equations
W5500 multi node connection
Want to record your supernatural moments when playing games? Let's take a look at how to use unity screenshots
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training
W5500上传温湿度到oneNET平台
Detailed explanation of zero basis from macro to micro Bert
SQL注入 Less23(过滤注释符)