{"id":4035,"date":"2022-06-03T06:18:50","date_gmt":"2022-06-03T06:18:50","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=4035"},"modified":"2022-06-03T06:18:50","modified_gmt":"2022-06-03T06:18:50","slug":"dart-basic-syntax","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/06\/03\/dart-basic-syntax\/","title":{"rendered":"Dart Basic Syntax"},"content":{"rendered":"\n<p>In this tutorial, we will learn the basic syntax of the Dart programming language.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Dart Identifiers<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<ul><li>The first character should not be a digit.<\/li><li>Special characters are not allowed except underscore (_) or a dollar sign ($).<\/li><li>Two successive underscores (__) are not allowed.<\/li><li>The first character must be alphabet(uppercase or lowercase) or underscore.<\/li><li>Identifiers must be unique and cannot contain whitespace.<\/li><li>They are case sensitive. The variable name&nbsp;<strong>Joseph<\/strong>&nbsp;and&nbsp;<strong>joseph<\/strong>&nbsp;will be treated differently.<\/li><\/ul>\n\n\n\n<p>Below is the table of valid and invalid identifiers.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><th>Valid Identifiers<\/th><th>Invalid Identifiers<\/th><\/tr><tr><td>firstname<\/td><td>__firstname<\/td><\/tr><tr><td>firstName<\/td><td>first name<\/td><\/tr><tr><td>var1<\/td><td>V5ar<\/td><\/tr><tr><td>$count<\/td><td>first-name<\/td><\/tr><tr><td>_firstname<\/td><td>1result<\/td><\/tr><tr><td>First_name<\/td><td>@var<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Dart Printing and String Interpolation<\/h2>\n\n\n\n<p>The&nbsp;<strong>print()<\/strong>&nbsp;function is used to print output on the console, and&nbsp;<strong>$expression<\/strong>&nbsp;is used for the string interpolation. Below is an example.<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main()  \n{  \n    var name = \"Peter\";  \n    var roll_no = 24;  \n    print(\"My name is ${name} My roll number is ${roll_no}\");  \n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>My name is Peter My roll number is 24\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Semicolon in Dart<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var msg1 = \"Hello World!\";  \nvar msg2 = \"How are you?\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Dart Whitespace and Line Breaks<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Block in Dart<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{ \/\/start of the block   \n  \n    \/\/block of statement(s)  \n  \n}\/\/ end of the block  <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Dart Command-Line Options<\/h2>\n\n\n\n<p>The Dart command-line options are used to modify Dart script execution. The standard command-line options are given below.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><th>Sr.<\/th><th>Command-line Options<\/th><th>Descriptions<\/th><\/tr><tr><td>1.<\/td><td>-c or -c<\/td><td>It allows both assertion and type checks.<\/td><\/tr><tr><td>2.<\/td><td>&#8211;version<\/td><td>It shows VM version information.<\/td><\/tr><tr><td>3.<\/td><td>&#8211;package&lt;path&gt;<\/td><td>It indicates the path to the package resolution configuration file.<\/td><\/tr><tr><td>4.<\/td><td>-p &lt;path&gt;<\/td><td>It indicates where to find the libraries.<\/td><\/tr><tr><td>5.<\/td><td>-h or -help<\/td><td>It is used to seek help.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Enable Checked Mode<\/h2>\n\n\n\n<p>Generally, the Dart program runs in two modes which are given below.<\/p>\n\n\n\n<ul><li>Checked Mode<\/li><li>Production Mode<\/li><\/ul>\n\n\n\n<p><strong>Checked Mode &#8211;<\/strong>&nbsp;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 &#8211;checked option in the command prompt before the dart script-file name. By default, the Dart VM runs in the checked mode.<\/p>\n\n\n\n<p><strong>Production Mode &#8211;<\/strong>&nbsp;The Dart script runs in the production mode. It provides assurance of performance enhancement while running the script. Consider the following example.<\/p>\n\n\n\n<p>Example &#8211;<a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {   \n   int var = \"hello\";   \n   print(var);   \n}  <\/code><\/pre>\n\n\n\n<p>Now activate the checked mode by typing dart -c or &#8211;checked mode<\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><\/p>\n\n\n\n<ol><li>dart&nbsp;-c&nbsp;mode.dart&nbsp;&nbsp;<\/li><\/ol>\n\n\n\n<p>The Dart VM will through the following error.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-basic-syntax#\"><\/a><\/p>\n\n\n\n<ol><li>Unhandled&nbsp;exception:&nbsp;&nbsp;&nbsp;<\/li><li class=\"\">type&nbsp;&#8216;String&#8217;&nbsp;is&nbsp;not&nbsp;a&nbsp;subtype&nbsp;of&nbsp;type&nbsp;&#8216;int&#8217;&nbsp;of&nbsp;&#8216;n&#8217;&nbsp;where&nbsp;&nbsp;&nbsp;<\/li><li>&nbsp;&nbsp;&nbsp;String&nbsp;is&nbsp;from&nbsp;dart:core&nbsp;&nbsp;&nbsp;<\/li><li class=\"\">&nbsp;&nbsp;&nbsp;<strong>int<\/strong>&nbsp;is&nbsp;from&nbsp;dart:core&nbsp;&nbsp;&nbsp;<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will learn the basic syntax of the Dart programming language. Dart Identifiers 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[854],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/4035"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=4035"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/4035\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=4035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=4035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=4035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}