当前位置:网站首页>JS variable types and common type conversions
JS variable types and common type conversions
2022-07-06 12:09:00 【Aboci Bang】
JS Variable type
The original type :Number、String、Boolern、undefined、NULL– Store in the stack
Reference type :Object -- Store in the pile
1. Numerical type –Number: Numbers
(1) integer : Positive and negative integers and zero
(2) floating-point : decimal (1.11e+1 = 11.1)
2. String type –String
single quote (‘abc’)、 Double quotes (“abc”)、 Template string (``) Wrapped character set .
3. Boolean type –Boolern
true and false
4. Undefined type –undefined
5. Empty type –NULL
Its type is actually an object
6. object type –Object
Objects store properties and methods
var obj = {
a:a,
b:func1
}
classification :
Host object The host is the environment
There are two kinds of environments that the front end contacts :
1. Browser environment -- Provided window object ( Global object ) And its children
2. Server environment – nodejs Environment provided – global object ( Global object ) And its children
Both environments can run js Code .
The same thing is that they all use ChromeV8 engine – Because it is the highest performance engine at present
The difference is The two environments provide API Different
Built-in objects
JavaScript Provides some built-in objects and functions :
String、Math、Date、Array…
Custom object
Class instantiation object defined by ourselves
7.Symbol type
Please check the details
https://es6.ruanyifeng.com/#docs/symbol
7.BigInt type
var bg = 121212n; // Add... After the number ‘n’
Be careful :
1.BigInt Type cannot be used Math Object method .
2. Unable to join Number Example hybrid operation .
Type conversion
It is divided into : Implicit conversion and cast
Other types are converted to numbers :
Implicit conversion – Automatic conversion during program operation 

The plus sign is compared with other operators first except Arithmetic operation also String concatenation The role of
As shown in the figure above : Spliced strings have priority over arithmetic operations ( Will first string splicing If there is no string splicing, the arithmetic operation will be performed )
true Implicitly convert to 1
false and null Implicitly convert to 0
undefined Into the NaN =>Not a Number
reduce 、 ride 、 except 、 modulus Can convert a string into a number Convert a number to a string (1+’’) that will do
~~ Operators can be used properly to easily convert strings and numbers into each other in work
NaN operation 
NaN The results of mathematical operations are NaN Even if it's NaN It is also NaN
The function used for implicit conversion is Number
Coercive transformation – Manual switching
Forced conversion to numbers
Number(‘1’) //1
Number(‘1a’) //NaN
Number(true) //1
Number(false) //0
Number(undefined) //NaN
Number(null) //0
Forced to integer
You can only turn numbers Encounter letters or decimal points or other characters Stop intercepting The result of conversion failure is NaN
parseInt Back to decimal perhaps NaN, It has two parameters parseInt( Values to convert , Converted base ) The first white space character of the string is ignored
Force conversion to floating point 
Encounter letters, etc Stop intercepting The result of conversion failure is NaN The first white space character of the string is ignored
Force to string 
notes : If directly in numbers 、true And so on API You can use Numbers + Space +.API
Strong to Boolean 
Turn Boolean to false Of situation :’’ NaN 0 null undefined
Implicitly convert to Boolean
!!num // Double exclamation + Variable name
~~// I often write this in the program First, verify the errors we can expect at the beginning of the method If something goes wrong be return;
if(!num){
// Error prompt code
return;
}
边栏推荐
猜你喜欢

【ESP32学习-2】esp32地址映射

Arduino JSON data information parsing

Cannot change version of project facet Dynamic Web Module to 2.3.

Correspondence between STM32 model and contex M

Variable star user module
![[esp32 learning-1] construction of Arduino esp32 development environment](/img/31/dc16f776b7a95a08d177b1fd8856b8.png)
[esp32 learning-1] construction of Arduino esp32 development environment

Apprentissage automatique - - régression linéaire (sklearn)

共用体(union)详解【C语言】

Implementation scheme of distributed transaction

电商数据分析--薪资预测(线性回归)
随机推荐
C language callback function [C language]
机器学习--线性回归(sklearn)
Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
ESP learning problem record
机器学习--决策树(sklearn)
电商数据分析--用户行为分析
ToggleButton实现一个开关灯的效果
MySQL数据库面试题
STM32 how to locate the code segment that causes hard fault
Reading notes of difficult career creation
数据分析之缺失值填充(重点讲解多重插值法Miceforest)
Characteristics, task status and startup of UCOS III
物联网系统框架学习
MySQL占用内存过大解决方案
Analysis of charging architecture of glory magic 3pro
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries(XGBoost)
ESP8266通过Arduino IDE连接Onenet云平台(MQTT)
Programmers can make mistakes. Basic pointers and arrays of C language
arduino UNO R3的寄存器写法(1)-----引脚电平状态变化
C language, log print file name, function name, line number, date and time