Appearance
NullableUndefineableJSAnyExtension
extension NullableUndefineableJSAnyExtension on JSAny?Helper members to determine if a value is JavaScript undefined or null.
INFO
The members within these extensions may throw depending on the platform. Do not rely on them to be platform-consistent.
JavaScript undefined and JavaScript null are internalized differently based on the backend. When compiling to JavaScript, Dart null can actually be JavaScript undefined or JavaScript null. When compiling to Wasm, that's not the case: there's only one Wasm value null can be. Therefore, when an interop API returns JavaScript null or JavaScript undefined, they are both converted to Dart null when compiling to Wasm, and when you pass a Dart null to an interop API, it is called with JavaScript null. When compiling to JavaScript, Dart null retains its original JavaScript value. Avoid writing code where this distinction between null and undefined matters.
Properties
isDefinedAndNotNull extension no setter
bool get isDefinedAndNotNullAvailable on JSAny, provided by the NullableUndefineableJSAnyExtension extension
Implementation
dart
bool get isDefinedAndNotNull => !isUndefinedOrNull;isNull extension no setter
bool get isNullWhether this value corresponds to JavaScript null.
INFO
Currently, there is no way to distinguish between JavaScript undefined and JavaScript null when compiling to Wasm. Therefore, this getter should only be used for code that compiles to JavaScript and will throw when compiling to Wasm.
Available on JSAny, provided by the NullableUndefineableJSAnyExtension extension
Implementation
dart
external bool get isNull;isUndefined extension no setter
bool get isUndefinedWhether this value corresponds to JavaScript undefined.
INFO
Currently, there is no way to distinguish between JavaScript undefined and JavaScript null when compiling to Wasm. Therefore, this getter should only be used for code that compiles to JavaScript and will throw when compiling to Wasm.
Available on JSAny, provided by the NullableUndefineableJSAnyExtension extension
Implementation
dart
external bool get isUndefined;isUndefinedOrNull extension no setter
bool get isUndefinedOrNullAvailable on JSAny, provided by the NullableUndefineableJSAnyExtension extension
Implementation
dart
bool get isUndefinedOrNull => this == null;