Skip to content
On this page

幂运算符(ES7/ES2016)

** 等同于 Math.pow()

js
// 手写 pow 函数
function pow(m, n) {
	let res = 1
	for (let i = 0; i < n; i++) {
		res *= x
	}
	return res
}
console.log(pow(2, 10)) // 1024
console.log(2 ** 10) // 1024 两个星号之间不能分开

Released under the MIT License.