Dart Basic Syntax
In this tutorial, we will learn the basic syntax of the Dart programming language.
Identifiers are the name which is used to define variables, methods, class, and function, etc. An Identifier is a sequence of the letters([A to Z],[a to z]), digits([0-9]) and underscore(_), but remember that the first character should not be a numeric. There are a few rules to define identifiers which are given below.
Below is the table of valid and invalid identifiers.
Dart Printing and String Interpolation
The print() function is used to print output on the console, and $expression is used for the string interpolation. Below is an example.
My name is Peter My roll number is 24
Semicolon in Dart
The semicolon is used to terminate the statement that means, it indicates the statement is ended here. It is mandatory that each statement should be terminated with a semicolon(;). We can write multiple statements in a single line by using a semicolon as a delimiter. The compiler will generate an error if it is not use properly.
Dart Whitespace and Line Breaks
The Dart compiler ignores whitespaces. It is used to specify space, tabs, and newline characters in our program. It separates one part of any statement from another part of the statement. We can also use space and tabs in our program to define indentation and provide the proper format for the program. It makes code easy to understand and readable.
Block in Dart
The block is the collection of the statement enclosed in the curly braces. In Dart, we use curly braces to group all of the statements in the block. Consider the following syntax.
Dart Command-Line Options
The Dart command-line options are used to modify Dart script execution. The standard command-line options are given below.
Enable Checked Mode
Generally, the Dart program runs in two modes which are given below.
Checked Mode - The checked mode enables various checks in the Dart code, such as type-checking. It warns or throws errors while developing processes. To start the checked mode, type -c or --checked option in the command prompt before the dart script-file name. By default, the Dart VM runs in the checked mode.
Production Mode - The Dart script runs in the production mode. It provides assurance of performance enhancement while running the script. Consider the following example.
Now activate the checked mode by typing dart -c or --checked mode
The Dart VM will through the following error.