符号+
的含义是什么?
使用示例:
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
答案 0 :(得分:1)
实际上,它是将值转换为Number
的JavaScript简写。从技术上讲,它是unary plus operator,是unary negation operator的补充。
let number = "1"
console.log(typeof number)
console.log(typeof +number)
console.log(+number)
console.log(typeof -number)
console.log(-number)
console.log(typeof +true)
console.log(+true)