The data types of Javascript do not include Symbol. JavaScript has 6 data types, namely Undefined, Null, Boolean, Number, String and Object.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
What does Javascript’s data type not include?
##This article is based on (Advanced Programming with JavaScript (3rd Edition)) Summary
The six major data types of JavaScript (excluding Symbol)
Undefined,
Null,
Boolean,
Number,
String and
Object
are 7 in ES6 There is an additional data type Symbol, which is not covered in this article.
Undefined means undefined,
Null means empty,
Boolean represents a Boolean value,
Number represents a numerical value, and String represents a string.
Usually we can use the
typeof operator to detect the data type of a variable.
Note that typeof is an operator! Operator! Operator!The typeof operator applies the following rules:
- "undefined"
- This value is undefined.
- "boolean"
——This value is a Boolean value
- "string"
——This value is a string
- "number"
——This value is a numerical value
- "object"
——This value is an object or Null
- "function"
——This value is the function
str="I am String type":
<p style="line-height: normal;">console.log(typeof str) //"string" 注意typeof操作符的返回的结果是字符串<br/></p>For the typeof operator, there are A little weird thing is:
1. typeof returns
"object" for
null,
2. typeof returns
"undefined for undeclared variables "
3. typeof also returns
"undefined"
var s = null console.log(typeof s) //"object" console.log(typeof a) //"undefined", 注意变量a未声明 var b; console.log(typeof b) //"undefined", 注意变量b声明但未初始化for variables that are declared but not initialized, because of the weird characteristics of
typeof, and we also To learn more about the specific information of the variable, we often use instanceof to determine the data type of the variable.
Undefined and
Null types have only one value, which are
undefined and
null respectively .
For
undefined, you need to remember the following two points:
- The value of a variable that has been declared but not initialized is
- undefined
(refer to the above code )
- undefined
is equal to
null
console.log(undefined == null) //true
null, you need to remember two points:
- typeof null
Returns
"object". Logically, null is a reference to object (for examples, see
typeof)
- undefined
is equal to
null
Boolean type has two values - —
true and
false.
Any data can call the Boolean function
Boolean(), which will return a Boolean value.
true | false | |
---|---|---|
true | false | |
Non-zero string | ""(empty string) | |
Non-zero numbers (including infinity) | 0 and NaN | |
Any object | null | |
Not applicable | undefined | |
Not applicable | null |
字面量 | 含义 |
---|---|
\n | 换行符 |
\t | 制表符 |
\b | 退格符 |
\r | 回车符 |
\f | 换页符 |
\ | 斜杠 |
\’ | 单引号 |
\” | 双引号 |
\xnn | x表示十六进制, n为0-F, nn表示一个字符. 如\x41表示”A” |
\unnnn | u表示Unicode, 也为十六进制. nnnn表示一个十六进制的Unicode字符 |
例如:
console.log("这是单引号: \'") //这是单引号: 'console.log("这是\n换行符")/* 这是 换行符 */console.log("这是大写字母: \x41") //这是大写字母: A
转换为字符串 toString()和String()
大部分值都有toString()方法, 因此我们可以使用这个方法.
var a = 2console.log(a.toString()) //2var b = trueconsole.log(b.toString()) //true
还可以给toString()
添加一个参数, 这个参数表示基数.
var num = 7console.log(num.toString(2)) //111console.log(num.toString(3)) //21
前面说了大部分值可以使用toString()
方法, 那么哪些值不能使用呢? 那就是null
和undefined
.
当我们需要将一个变量A转换为字符串时, 假如我们不知道变量A是否是null
和undefined
, 我们可以使用String()
函数. 这个函数可以讲任意类型的值转换为字符串. 其规则如下:
- 如果可以调用
toString()
方法则调用该方法. - 如果是
null
, 则返回"null"
- 如果是
undefined
, 则返回"undefined"
Object
Object
类型俗称对象, 对象的实例通常使用new
操作符进行创建. 对象的实例还是对象, 我们会在对象的实例中添加属性和方法.
var obj = new Object();
Object
的实例有下列基本的属性和方法:
-
constructor
constructor
属性保存着穿件当前对象的函数, 也叫构造函数. 如上例中的Object()
-
hasOwnProperty(propertyName)
这个方法用于检测当前对象实例中是否有属性名为propertyName
的属性.propertyName
必须为字符串 -
isPrototypeOf(object)
其用于检查传入的对象object是否为当前对象实例的原型 -
propertyIsEnumerable(propertyName)
用于检查给定的属性propertyName
是否可以用for-in
语句来枚举.propertyName
必须为字符串 -
toLocaleString()
,toString()
,valueOf()
这三个方法都可以返回对象的字符串表示,valueOf()
还可以返回对象的数值, 布尔值表示.
可以参考这篇文章:Javascript toString()、toLocaleString()、valueOf()三个方法的区别-博客园-一个悬浮在空中的胖子
var obj = new Object() obj.constructor //ƒ Object() { [native code] }obj.name = "ES" //给obj添加属性obj.hasOwnProperty("name") //true, 注意参数必须为字符串形式obj.propertyIsEnumerable("name") //trueobj.toString() //"[object Object]"
推荐学习:《javascript高级教程》
The above is the detailed content of What does Javascript data type not include?. For more information, please follow other related articles on the PHP Chinese website!

Classesarebetterforaccessibilityinwebdevelopment.1)Classescanbeappliedtomultipleelements,ensuringconsistentstylesandbehaviors,whichaidsuserswithdisabilities.2)TheyfacilitatetheuseofARIAattributesacrossgroupsofelements,enhancinguserexperience.3)Classe

Classselectorsarereusableformultipleelements,whileIDselectorsareuniqueandusedonceperpage.1)Classes,denotedbyaperiod(.),areidealforstylingmultipleelementslikebuttons.2)IDs,denotedbyahash(#),areperfectforuniqueelementslikeanavigationmenu.3)IDshavehighe

In CSS style, the class selector or ID selector should be selected according to the project requirements: 1) The class selector is suitable for reuse and is suitable for the same style of multiple elements; 2) The ID selector is suitable for unique elements and has higher priority, but should be used with caution to avoid maintenance difficulties.

HTML5hasseverallimitationsincludinglackofsupportforadvancedgraphics,basicformvalidation,cross-browsercompatibilityissues,performanceimpacts,andsecurityconcerns.1)Forcomplexgraphics,HTML5'scanvasisinsufficient,requiringlibrarieslikeWebGLorThree.js.2)I

Yes,onestylecanhavemoreprioritythananotherinCSSduetospecificityandthecascade.1)Specificityactsasascoringsystemwheremorespecificselectorshavehigherpriority.2)Thecascadedeterminesstyleapplicationorder,withlaterrulesoverridingearlieronesofequalspecifici

ThesignificantgoalsofHTML5aretoenhancemultimediasupport,ensurehumanreadability,maintainconsistencyacrossdevices,andensurebackwardcompatibility.1)HTML5improvesmultimediawithnativeelementslikeand.2)ItusessemanticelementsforbetterreadabilityandSEO.3)Its

React'slimitationsinclude:1)asteeplearningcurveduetoitsvastecosystem,2)SEOchallengeswithclient-siderendering,3)potentialperformanceissuesinlargeapplications,4)complexstatemanagementasappsgrow,and5)theneedtokeepupwithitsrapidevolution.Thesefactorsshou

Reactischallengingforbeginnersduetoitssteeplearningcurveandparadigmshifttocomponent-basedarchitecture.1)Startwithofficialdocumentationforasolidfoundation.2)UnderstandJSXandhowtoembedJavaScriptwithinit.3)Learntousefunctionalcomponentswithhooksforstate


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools
