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

边栏推荐
- Fillet big killer, use filter to build fillet and wave effect!
- 如何解决“W5500芯片在TCP_Client模式下,断电重启之后无法立即连接到服务器”的问题
- Common web attacks and defense
- Teach you how to configure S2E as the working mode of TCP server through MCU
- Hardware peripherals =maixpy3
- DICOM medical image viewing and browsing function based on cornerstone.js
- SQL注入 Less23(过滤注释符)
- Attendance system based on w5500
- 教你如何通过MCU将S2E配置为UDP的工作模式
- Txt to CSV file, blank lines appear every other line
猜你喜欢
随机推荐
Only know that the preform is used to generate objects? See how I use unity to generate UI prefabs
贪心问题01_活动安排代码分析
Small and micro enterprise smart business card management applet
Filter过滤器解决request请求参数乱码的原理解析
Game backpack system, "inventory Pro plug-in", research and learning ----- mom doesn't have to worry that I won't make a backpack anymore (unity3d)
Shell Chapter 5 homework
常见WEB攻击与防御
OneNET平台控制W5500开发板LED灯
JVM性能调优方法
RedisUtil
教你如何通过MCU配置S2E为TCP Client的工作模式
如何判断静态代码质量分析工具的性能?这五大因素必须考虑
第4章线性方程组
JS运算符
【USB设备设计】--复合设备,双HID高速(64Byte 和 1024Byte)
Miidock Brief
toString()与new String()用法区别
Fillet big killer, use filter to build fillet and wave effect!
[leetcode brush questions]
Talking about Devops monitoring, how does the team choose monitoring tools?









