Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
4
Help us understand the problem. What is going on with this article?
@munieru_jp

Google Apps ScriptにはNumber.isNaN()がない

More than 1 year has passed since last update.

Google Apps ScriptでNumber.isNaN()を使おうとしたところ、以下のようなエラーが発生しました。

TypeError: オブジェクト function Number() { [native code for Number.Number, arity=1] } で関数 isNaN が見つかりません。

そう、Google Apps ScriptにはNumber.isNaN()がないのです。
グローバル関数のisNaN()はありますが、こちらは仕様に問題があるので使わないほうがいいでしょう。1

対処法

Number.isNaN()と同等の処理は簡単に実装できるので、isNaN_関数を作ってそれを使いましょう。

Google Apps Scriptで書く場合

function isNaN_ (value) {
  return typeof value === 'number' && value !== value
}

TypeScriptで書く場合

function isNaN_ (value: any): boolean {
  return typeof value === 'number' && value !== value
}

参考リンク

4
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
munieru_jp
江戸川区在住のアプリケーションエンジニア
decrements
We build nothing to not enhance software development.

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
4
Help us understand the problem. What is going on with this article?