Skip to content

Files

Latest commit

 

History

History
35 lines (28 loc) · 597 Bytes

avoid_double_and_int_checks.md

File metadata and controls

35 lines (28 loc) · 597 Bytes

Pattern: Use of double/int check

Issue: -

Description

When compiled to JS, integer values are represented as floats. That can lead to some unexpected behavior when using either is or is! where the type is either int or double.

Example of incorrect code:

f(num x) {
 if (x is double) {
  ...
 } else if (x is int) {
  ...
 }
}

Example of correct code:

f(dynamic x) {
 if (x is num) {
  ...
 } else {
  ...
 }
}

Further Reading