admin管理员组文章数量:1303345
There is a line of code in angular2.
this.id = +this.route.snapshot.params['id'];
What is the "+" means before "this.route.snapshot.params['id']"?
I also see "+" added before a folder name such as "+detail" in angular2-webpack-starter.
Do they have the same meaning?
There is a line of code in angular2.
this.id = +this.route.snapshot.params['id'];
What is the "+" means before "this.route.snapshot.params['id']"?
I also see "+" added before a folder name such as "+detail" in angular2-webpack-starter.
Do they have the same meaning?
Share edited Mar 7, 2017 at 22:19 georgeawg 49k13 gold badges77 silver badges98 bronze badges asked Mar 7, 2017 at 21:11 HenryHenry 1732 silver badges10 bronze badges 1-
2
+
is used for a quick changing type of number-ishstrings
intonumber
, e.g.+"5"
will return5
. – kind user Commented Mar 7, 2017 at 21:14
2 Answers
Reset to default 11Using + in Javascript is a quick way to cast a string to a number as long as the string is already in the form of an integer or float.
+'5000' // yields 5000
+'2.5' // yields 2.5
If the string contains any character that is not an integer (or decimal in the case of a float), this method will return NaN.
+'5n' // yields NaN
+'abcd' // yields NaN
enter image description here
In short if you put + operator in front of string which contains Number then always get number other than that you will get NaN.
本文标签: What does abefore a string means in javascriptStack Overflow
版权声明:本文标题:What does a + before a string means in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741695460a2392978.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论