您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
Ready 发布于2014年08月05日 03:17

原创 JavaScript Math.sqrt() 函数详解

6561 次浏览 读完需要≈ 3 分钟

内容目录

Math.sqrt()函数用于返回一个数的平方根

该函数属于JavaScript的内置全局对象Math所有主流浏览器均支持该函数

语法

静态函数Math.sqrt()的语法如下:

Math.sqrt( number )

参数

参数 描述
number Number类型指定的数,以计算该数的平方根

返回值

Math.sqrt()的返回值为Number类型。返回number的平方根。

传入的参数必须为非负数,否则返回NaN

示例&说明

document.writeln( Math.sqrt( 1.512 ) ); // 1.2296340919151518

document.writeln( Math.sqrt( -2.3 ) ); // NaN

document.writeln( Math.sqrt( 0 ) ); // 0

document.writeln( Math.sqrt( 9 ) ); // 3

// 传入的参数为NaN值
document.writeln( Math.sqrt( "CodePlayer" ) ); // NaN

运行代码

  • CodePlayer技术交流群1
  • CodePlayer技术交流群2

0 条评论

撰写评论

打开导航菜单