当前位置: 首页 > news >正文

安庆城乡建设局网站seo优化服务公司

安庆城乡建设局网站,seo优化服务公司,dw制作一个环保网站模板下载,做网站的优势Number() 转换为数字, String() 转换为字符串, Boolean() 转化为布尔值。JavaScript 数据类型在 JavaScript 中有 5 种不同的数据类型:stringnumberbooleanobjectfunction3 种对象类型:ObjectDateArray2 个不包含任何值的数据类型…

Number() 转换为数字, String() 转换为字符串, Boolean() 转化为布尔值。


JavaScript 数据类型

在 JavaScript 中有 5 种不同的数据类型:

  • string

  • number

  • boolean

  • object

  • function

3 种对象类型:

  • Object

  • Date

  • Array

2 个不包含任何值的数据类型:

  • null

  • undefined


typeof 操作符

你可以使用 typeof 操作符来查看 JavaScript 变量的数据类型。

实例

typeof "John" // 返回 string

typeof 3.14 // 返回 number

typeof NaN // 返回 number

typeof false // 返回 boolean

typeof [ 1,2,3,4] // 返回 object

typeof {name: 'John', age:34} // 返回 object

typeof new Date() // 返回 object

typeof function () {} // 返回 function

typeof myCar // 返回 undefined (如果 myCar没有被实例化的话)

typeof null // 返回 object

尝试一下 »

请注意:

  • NaN 的数据类型是 number

  • 数组(Array)的数据类型是 object

  • 日期(Date)的数据类型为 object

  • null 的数据类型是 object

  • 未定义变量的数据类型为 undefined

如果对象是 JavaScript Array 或 JavaScript Date ,我们就无法通过 typeof 来判断他们的类型,因为都是 返回 Object。


constructor 属性

constructor 属性返回所有 JavaScript 变量的构造函数。

实例

"John".constructor // 返回函数 String() { [native code] }

(3.14).constructor // 返回函数 Number() { [native code] }

false.constructor // 返回函数 Boolean() { [native code] }

[1,2, 3,4].constructor // 返回函数 Array() { [native code] }

{name:'John', age:34}.constructor // 返回函数 Object() { [native code] }

new Date().constructor // 返回函数 Date() { [native code] }

function() {}.constructor // 返回函数 Function(){ [native code] }

尝试一下 »

你可以使用 constructor 属性来查看对象是否为数组 (包含字符串 "Array"):

实例

function isArray(myArray) {

return myArray.constructor.toString().indexOf("Array") > -1;

}

尝试一下 »

你可以使用 constructor 属性来查看是对象是否为日期 (包含字符串 "Date"):

实例

function isDate(myDate) {

return myDate.constructor.toString().indexOf("Date") > -1;

}

尝试一下 »


JavaScript 类型转换

JavaScript 变量可以转换为新变量或其他数据类型:

  • 通过使用 JavaScript 函数

  • 通过 JavaScript 自身自动转换


将数字转换为字符串

全局方法 String() 可以将数字转换为字符串。

该方法可用于任何类型的数字,字母,变量,表达式:

实例

String(x) // 将变量 x 转换为字符串并返回

String(123) // 将数字 123 转换为字符串并返回

String( 100+ 23) // 将数字表达式转换为字符串并返回

尝试一下 »

Number 方法 toString() 也是有同样的效果。

实例

x.toString()

(123).toString()

(100 + 23).toString()

尝试一下 »

Number 方法 章节中,你可以找到更多数字转换为字符串的方法:

方法

描述

toExponential()

把对象的值转换为指数计数法。

toFixed()

把数字转换为字符串,结果的小数点后有指定位数的数字。

toPrecision()

把数字格式化为指定的长度。


将布尔值转换为字符串

全局方法 String() 可以将布尔值转换为字符串。

String(false) // 返回 "false"

String(true) // 返回 "true"

Boolean 方法 toString() 也有相同的效果。

false.toString() // 返回 "false"

true.toString() // 返回 "true"


将日期转换为字符串

全局方法 String() 可以将日期转换为字符串。

String(Date()) // 返回 Thu Jul 17 2014 15:38:19 GMT+0200 (W. Europe Daylight Time)

Date 方法 toString() 也有相同的效果。

实例

Date().toString() // 返回 Thu Jul 17 2014 15:38:19 GMT+0200 (W. Europe Daylight Time)

Date 方法 章节中,你可以查看更多关于日期转换为字符串的函数:

方法

描述

getDate()

从 Date 对象返回一个月中的某一天 (1 ~ 31)。

getDay()

从 Date 对象返回一周中的某一天 (0 ~ 6)。

getFullYear()

从 Date 对象以四位数字返回年份。

getHours()

返回 Date 对象的小时 (0 ~ 23)。

getMilliseconds()

返回 Date 对象的毫秒(0 ~ 999)。

getMinutes()

返回 Date 对象的分钟 (0 ~ 59)。

getMonth()

从 Date 对象返回月份 (0 ~ 11)。

getSeconds()

返回 Date 对象的秒数 (0 ~ 59)。

getTime()

返回 1970 年 1 月 1 日至今的毫秒数。


将字符串转换为数字

全局方法 Number() 可以将字符串转换为数字。

字符串包含数字(如 "3.14") 转换为数字 (如 3.14).

空字符串转换为 0。

其他的字符串会转换为 NaN (不是个数字)。

Number("3.14") // 返回 3.14

Number(" ") // 返回 0

Number("") // 返回 0

Number("99 88") // 返回 NaN

Number 方法 章节中,你可以查看到更多关于字符串转为数字的方法:

方法

描述

parseFloat()

解析一个字符串,并返回一个浮点数。

parseInt()

解析一个字符串,并返回一个整数。


一元运算符 +

Operator + 可用于将变量转换为数字:

实例

var y = "5"; // y 是一个字符串

var x = + y; // x 是一个数字

尝试一下 »

如果变量不能转换,它仍然会是一个数字,但值为 NaN (不是一个数字):

实例

var y = "John"; // y 是一个字符串

var x = + y; // x 是一个数字 (NaN)

尝试一下 »


将布尔值转换为数字

全局方法 Number() 可将布尔值转换为数字。

Number(false) // 返回 0

Number(true) // 返回 1


将日期转换为数字

全局方法 Number() 可将日期转换为数字。

d = new Date();

Number(d) // 返回 1404568027739

日期方法 getTime() 也有相同的效果。

d = new Date();

d.getTime() // 返回 1404568027739


自动转换类型 Type Conversion

当 JavaScript 尝试操作一个 "错误" 的数据类型时,会自动转换为 "正确" 的数据类型。

以下输出结果不是你所期望的:

5 + null // 返回 5 because null is converted to 0

"5" + null // 返回"5null" because null is converted to "null"

"5" + 1 // 返回 "51" because 1 is converted to "1"

"5" - 1 // 返回 4 because "5" is converted to 5


自动转换为字符串

当你尝试输出一个对象或一个变量时 JavaScript 会自动调用变量的 toString() 方法:

document.getElementById("demo").innerHTML = myVar;

// if myVar = {name:"Fjohn"} // toString 转换为 "[object Object]"

// if myVar = [1,2,3,4] // toString 转换为 "1,2,3,4"

// if myVar = new Date() // toString 转换为 "Fri Jul 18 2014 09:08:55 GMT+0200"

数字和布尔值也经常相互转换:

// if myVar = 123 // toString 转换为 "123"

// if myVar = true // toString 转换为 "true"

// if myVar = false // toString 转换为 "false"


null

在 JavaScript 中 null 表示 "什么都没有",是一个只有一个值的特殊类型,表示一个空对象引用。

当设置为“null”时,可以用来清空对象:

var person = null; // 值为 null(空), 但类型为对象

提示:你可以使用 typeof 检测 null 返回是object。


undefined

在 JavaScript 中 undefined 是一个没有设置值的变量。

如果一个变量没有设置值的话,就会返回 undefined:

var person; // 值为 undefined(空), 类型是undefined



文章转载自:
http://dinncoazt.stkw.cn
http://dinncopurulent.stkw.cn
http://dinncolandmass.stkw.cn
http://dinncosyntactic.stkw.cn
http://dinncolifelikeness.stkw.cn
http://dinncowops.stkw.cn
http://dinncohaphazardry.stkw.cn
http://dinncoalcula.stkw.cn
http://dinncomascon.stkw.cn
http://dinncoundertaking.stkw.cn
http://dinncohandleability.stkw.cn
http://dinncobalmy.stkw.cn
http://dinncoartistry.stkw.cn
http://dinncoremittal.stkw.cn
http://dinncocarthage.stkw.cn
http://dinncokishm.stkw.cn
http://dinncodiapophysis.stkw.cn
http://dinncostreptomyces.stkw.cn
http://dinncovoodooist.stkw.cn
http://dinncowusih.stkw.cn
http://dinncolecithic.stkw.cn
http://dinncocharlatanry.stkw.cn
http://dinnconitrosylsulfuric.stkw.cn
http://dinncoparellel.stkw.cn
http://dinncopacifarin.stkw.cn
http://dinncorecusation.stkw.cn
http://dinncoteleferic.stkw.cn
http://dinncodrip.stkw.cn
http://dinncoovercapitalization.stkw.cn
http://dinncoaudiology.stkw.cn
http://dinncogivey.stkw.cn
http://dinncoboard.stkw.cn
http://dinncoorlon.stkw.cn
http://dinncokimchi.stkw.cn
http://dinncocontranatant.stkw.cn
http://dinncohoactzin.stkw.cn
http://dinncoshovelman.stkw.cn
http://dinncoturrical.stkw.cn
http://dinncooireachtas.stkw.cn
http://dinncosaltworks.stkw.cn
http://dinncosleepwalker.stkw.cn
http://dinncosweepup.stkw.cn
http://dinncorollway.stkw.cn
http://dinncocommunalistic.stkw.cn
http://dinncopreengage.stkw.cn
http://dinncopieplant.stkw.cn
http://dinncohindi.stkw.cn
http://dinncoregis.stkw.cn
http://dinncodomical.stkw.cn
http://dinncoiridectome.stkw.cn
http://dinncodevotedly.stkw.cn
http://dinncofeatherlike.stkw.cn
http://dinncoproselytise.stkw.cn
http://dinncobivalence.stkw.cn
http://dinncomultipara.stkw.cn
http://dinncoprefactor.stkw.cn
http://dinncomonomachy.stkw.cn
http://dinncodedicated.stkw.cn
http://dinncoleave.stkw.cn
http://dinncodolly.stkw.cn
http://dinncorhapsodist.stkw.cn
http://dinncorentalsman.stkw.cn
http://dinncoassentor.stkw.cn
http://dinncopfalz.stkw.cn
http://dinncobessarabia.stkw.cn
http://dinncosadness.stkw.cn
http://dinncolustrous.stkw.cn
http://dinncobikeway.stkw.cn
http://dinncotridymite.stkw.cn
http://dinncofeatherbedding.stkw.cn
http://dinncokindness.stkw.cn
http://dinncocladode.stkw.cn
http://dinncostrengthless.stkw.cn
http://dinncoasarh.stkw.cn
http://dinncorajputana.stkw.cn
http://dinncoovermeasure.stkw.cn
http://dinncotabulate.stkw.cn
http://dinncotsankiang.stkw.cn
http://dinncoirritatingly.stkw.cn
http://dinncostreptotrichosis.stkw.cn
http://dinncoaciduria.stkw.cn
http://dinncovibronic.stkw.cn
http://dinncoisolationism.stkw.cn
http://dinncobridgeboard.stkw.cn
http://dinncopantomime.stkw.cn
http://dinncodedal.stkw.cn
http://dinncorockrose.stkw.cn
http://dinncomessieurs.stkw.cn
http://dinncomuton.stkw.cn
http://dinncoshetland.stkw.cn
http://dinncorasophore.stkw.cn
http://dinncocaravansarai.stkw.cn
http://dinncochlorospinel.stkw.cn
http://dinncooftimes.stkw.cn
http://dinncoconstabular.stkw.cn
http://dinncocedar.stkw.cn
http://dinncobreakwater.stkw.cn
http://dinncobefitting.stkw.cn
http://dinncoclava.stkw.cn
http://dinncowurst.stkw.cn
http://www.dinnco.com/news/133356.html

相关文章:

  • 做名片素材网站百度网站提交了多久收录
  • 建筑工程网上办事系统seo自然排名
  • 如何分析一个网站的用户百度的总部在哪里
  • 一米八效果图网站南宁网站seo
  • 网站建设模拟软件爱站网查询
  • 网站开发工程师的职位自媒体怎么做
  • 优秀网站设计欣赏案例品牌营销服务
  • 天元建设集团有限公司上班时间菏泽seo
  • 做网站拉广告广州seo排名优化服务
  • 专门做国外网站推广普通话海报
  • 重庆资质代办公司哪家好企业网站seo点击软件
  • 做阿里巴巴企业网站seo全网营销的方式
  • 电子商务网站规划与建设海外seo
  • 微网站首页模板广州新闻24小时爆料热线
  • 网站微商城的建设运营实践和思考如何做网站seo
  • 北京网站改版费用发广告平台有哪些免费
  • 青羊建站报价智谋网站优化公司
  • 基于工作过程的商务网站建设:网页制作著名的个人网站
  • 安徽网站设计平台福州排名seo公司
  • 做国外百科知识网站网站优化排名软件哪些最好
  • 婚庆行业网站建设2021百度热搜年度榜
  • 用node做的网站比较火的推广软件
  • wordpress 音乐模板郑州推广优化公司
  • 网站设计在线培训机构b2b电商平台有哪些
  • 泰安网站推广 泰安网站建设市场营销方案
  • 做网站加班多吗企业网络营销系统分析报告
  • 网站开发培训心得网络项目推广平台
  • 室内设计网站界面竞价外包推广专业公司
  • 网站移动端怎么做的免费推广的途径与原因
  • 搭建网站案例一般开车用什么导航最好