Skip to content

Instantly share code, notes, and snippets.

@matefs
Created May 17, 2023 12:30
Show Gist options
  • Save matefs/ad336aa56c42dfb25c327a51f5a54fc2 to your computer and use it in GitHub Desktop.
Save matefs/ad336aa56c42dfb25c327a51f5a54fc2 to your computer and use it in GitHub Desktop.
Dart x javascript table

Dart x Javascript

Command Dart JavaScript
Create a variable var myVar = "Hello, world!"; var myVar = "Hello, world!";
Print to the console print(myVar); console.log(myVar);
Create an array var myArray = ["a", "b", "c"]; var myArray = ["a", "b", "c"];
Add an item to an array myArray.add("d"); myArray.push("d");
Remove an item from an array myArray.remove("b"); myArray.splice(1, 1);
Get the length of an array myArray.length; myArray.length;
Create a function void myFunction() { print("Hello, world!"); } function myFunction() { console.log("Hello, world!"); }
Call a function myFunction(); myFunction();
Create an object var myObject = { "name": "John Doe", "age": 30 }; var myObject = { "name": "John Doe", "age": 30 };
Get a property from an object var myName = myObject["name"]; var myName = myObject.name;
Set a property on an object myObject["age"] = 31; myObject.age = 31;
Create a class class MyClass { String name; int age; MyClass({this.name, this.age}); void printInfo() { print("My name is $name and I am $age years old"); } } class MyClass { String name; int age; constructor(this.name, this.age); void printInfo() { console.log("My name is $name and I am $age years old"); } }
Create an instance of a class var myObject = new MyClass("John Doe", 30); var myObject = new MyClass("John Doe", 30);
Call a method on an object myObject.printInfo(); myObject.printInfo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment