0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【JavaScript】Stringの数字をNumberに変換方法

Last updated at Posted at 2019-05-23

Stringの数字をNumberに型変換したい時

const num = "12345";

console.log(typeof(num)) // String

console.log(typeof(Number(num))) // Number

console.log(typeof(parseInt(num,10))) // Number 第二引数は10進数ということ

console.log(typeof(+num)) // Number

いろんなやり方がありますね。
ただ、主流は+numをよく使うみたいです。

その前に、typeScriptで型を定めたほうがいいってことか。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?