当前位置:网站首页>Five simple data types of JS
Five simple data types of JS
2022-06-25 05:02:00 【Dai Sensen】
js Have dynamic types , It also means that the same variables can be used as different types , But here we only introduce js Five simple data types for , For complex data types (object) No introduction .
String( String type )
Definition
var str = ' character string ';
1. String type can be any text in quotation marks , Its grammar is Double quotes “” and Single quotation marks ’’
2. because HTML The attributes in the tag use double quotation marks ,JS Here we recommend using single quotation marks .
String quotes nested JS
You can use single quotes to nest double quotes , Or use double quotes to nest single quotes ( Double outside and single inside , Single outside and double inside )
var strMsg = ' I am a " Gao Shuai Fu " Program the ape '; // It can be used '' contain ""
var strMsg2 = " I am a ' Gao Shuai Fu ' Program the ape "; // It can also be used. "" contain ''
// Common mistakes
var badQuotes = 'What on earth?"; // Report errors , You can't Single and double quotation marks
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 :

String length
A string is made up of several characters , The number of these characters is the length of the string . Through strings length Property to get the entire character The length of the string .
var strMsg = " I'm a handsome and golden procedural ape !";
alert(strMsg.length); // Show 11
String splicing
1 You can use... Between multiple strings + Splicing , The splicing method is character string + Any kind of = The new string after splicing
2 Any type added to the string will be converted into a string before splicing , And then splice it into a new string
//1.1 character string " Add up "
alert('hello' + ' ' + 'world'); // hello world
//1.2 Numeric strings " Add up "
alert('100' + '100'); // 100100
//1.3 Numeric strings + The number
alert('11' + 12); // 1112
1 We often splice strings and variables , Because variables can easily modify the values inside 2 Variables cannot be quoted , Because quoted variables become strings
3 If you have string concatenation on both sides of the variable , formula “ Lead and add ”, Cut out the numbers , Variable write and middle
console.log('pink teacher ' + 18); // As long as there are characters, they will be connected
var age = 18;
// console.log('pink teacher age Years old! '); // That's not going to work
console.log('pink teacher ' + age); // pink teacher 18
console.log('pink teacher ' + age + ' Years old! '); // pink teacher 18 Years old!
Number( Digital )
JavaScript Numeric types can be used to hold integer values , You can also save decimals ( Floating point numbers ).
var age = 21; // Integers
var Age = 21.3747; // decimal
Digital base system
The most common system is binary 、 octal 、 Decimal system 、 Hexadecimal . At this stage, we just need to remember , stay JS Add... Before the octal 0, Hexadecimal is preceded by 0x
// 1. Octal number sequence range :0~7
var num1 = 07; // Corresponding to the decimal 7
var num2 = 019; // Corresponding to the decimal 19
var num3 = 08; // Corresponding to the decimal 8
// 2. Range of hexadecimal number sequence :0~9 as well as A~F
var num = 0xA;
Digital range
JavaScript The maximum and minimum of the values in
Maximum :Number.MAX_VALUE, The value of 1.7976931348623157e+308
minimum value :Number.MIN_VALUE, The value of :5e-32
alert(Number.MAX_VALUE); // 1.7976931348623157e+308
alert(Number.MIN_VALUE); // 5e-324
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
alert(Infinity); // Infinity
alert(-Infinity); // -Infinity
alert(NaN); // NaN
isNaN()
Used to determine whether a variable is a non numeric type , return true perhaps false
var usrAge = 21;
var isOk = isNaN(userAge);
console.log(isNum); // false ,21 It's not a non number
var usrName = "andy";
console.log(isNaN(userName)); // true ,"andy" It's a non number
Boolean( Boolean type )
The boolean type has two values :true and false , among true Said really ( Yes ), and false Said the false ( wrong ). When Boolean and number are added ,
true The value of is 1 ,false The value of is 0.
console.log(true + 1); // 2
console.log(false + 1); // 1
Undefined ( Data type not defined )
A variable that is not assigned after declaration has a default value undefined ( If you join or add , Pay attention to the results )
var variable;
console.log(variable); // undefined
console.log(' Hello ' + variable); // Hello undefined
console.log(11 + variable); // NaN
console.log(true + variable); // NaN
Null( Null value )
A declaration variable is given to null value , The value stored in it is empty ( When learning objects , We continue to study null)
var vari = null;
console.log(' Hello ' + vari); // Hello null
console.log(11 + vari); // 11
console.log(true + vari); // 1
边栏推荐
- How to install the blue lake plug-in to support Photoshop CC 2017
- Creation and use of MySQL index
- "Daily practice, happy water" 1108 IP address invalidation
- 【FLink】access closed classloader classloader. check-leaked-classloader
- Heavy broadcast | phase shift method + mathematical principle derivation of multi frequency heterodyne + implementation
- Abuse unlimited authorization -- is your address safe?
- 融合CDN,为客户打造极致服务体验!
- Detailed summary of position positioning
- Why is the TCP handshake just 3 times?
- PHP uses JWT
猜你喜欢

SQL lab range explanation

固态硬盘开盘数据恢复的方法

Vscade setting clang format

Deeply understand the characteristics of standard flow and off standard elements

Matlab notes

Successfully solved: selenium common. exceptions. TimeoutException: Message: timeout: Timed out receiving message from

How to install the blue lake plug-in to support Photoshop CC 2017

EL & JSTL (XIII)

Kotlin compose listens to the soft keyboard and clicks enter to submit the event

olap分析引擎——Kylin4.0
随机推荐
How PHP gets the user's City
Summary of SQL injection (I)
XSS (cross site script attack) summary (II)
【Flink】RocksDB增量模式checkpoint大小持续增长的问题及解决
Redis (17)
How to open the DWG file of the computer
2021-04-02
Fun CMD command line~
Virtual honeypot Honeyd installation and deployment
Attack and defense world web baby Web
Sleep more, you can lose weight. According to the latest research from the University of Chicago, sleeping more than 1 hour a day is equivalent to eating less than one fried chicken leg
Get to know the drawing component of flutter - custompaint
Laravel Vonage SMS sending
CSRF (Cross Site Request Forgery) &ssrf (server request forgery) (IV)
成功解决:selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from
ASEMI大功率场效应管和三极管的区别
固态硬盘开盘数据恢复的方法
Implementation of websocket long connection by workman under laravel
以太网是什么要怎么连接电脑
Efficient NoSQL database service Amazon dynamodb experience sharing