Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon graphicbeacon/main.dart
Last active Apr 6, 2019

Embed
What would you like to do?
Snippet comparing Dart conventions to JS
import 'dart:html';
import 'dart:math' as Math;
main() {
// 1 - Sorting arrays
var arr = [1, 2, 3, 15, 30, 7, 5, 45, 60];
arr.sort();
print(arr);
// 2 - Adding lists/arrays
print([1, 2, 3] + [4, 5, 6]);
// 3 - Document.all
window.console.log(document.childNodes);
window.console.log(document.childNodes[2]);
print(document.childNodes.runtimeType);
print({} is Map);
print(document.childNodes is NodeList);
// 4 - Regular Expressions
var re = RegExp('Foo B');
print(re.hasMatch('Foo Bar'));
print(re.hasMatch('Foo Bar'));
// 5 - Math.max behaviour
Math.max(3, 0);
// Math.max(3, {});
// Math.max(3, []);
// Math.max(3, true);
// Math.max(3, 'foo');
// Math.max(-1, null);
// Math.max(-1, undefined);
// 6 - Dates
// DateTime("couldn't you please throw an exception here instead?");
var d = DateTime.now();
print(d.day);
print(d.month);
// 7 - Null
print(null.runtimeType);
print(null is Object);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.