“Hello World” in Dart

As tradition has it, this is how you simply print out the text “Hello World” to the output console in Dart:

main() {
  print("Hello World");
}

There is a main() function, which is where every Dart program start executing your code.

  • main() is where your application starts.
  • the curly brackets { } indicate what code is part of the main function.
  • the print command tells the program to write something to an output console.
  • the parenthesis ( ) indicate what code is part of the print statement.
  • the double quotes ” ” indicate a string of text that should be part of what gets printed out to the console.
  • the semicolon ; at the end is the terminator, indicating the end of the print command.

Most of the time you will see a keyword like “void” in front of the function name like the following, which indicated this function does not return a value back, but simply just print the text to the console.

void main() {
  print("Hello World");
}

You will also usually see a comment in the code (indicated by the two forward slashes) explaining what the code is supposed to do or even just information about the code, like who wrote the code.

// This Dart program simply prints two words.
void main() {
  print("Hello World");
}

Go ahead and try this out using the free online editor called DartPad available here: https://dartpad.dartlang.org/

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published.

19 + 6 =