0
import scala.scalajs.js
import scala.scalajs.js.Date
import org.scalajs.dom.window.alert

val num: Double = new Date("a").getTime
alert((num + 1).toString)

This code reports NaN as the value of the alert. How do I know beforehand that num is a NaN in Scala.js code and not a proper Double?

1 Answer 1

0

Unless I misunderstood the question, you can test for NaN with the isNaN method:

if (num.isNaN)
  println("it is NaN")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.