<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ syntax - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ syntax - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sat, 30 May 2026 16:31:52 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/syntax/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Learn GitHub-Flavored Markdown Syntax and Formatting – With Examples ]]>
                </title>
                <description>
                    <![CDATA[ Markdown is a lightweight, open-source, easy-to-read and easy-to-write method of formatting text that you can use as plain text in any IDE or editor. When writing on GitHub, you can use Markdown syntax and HTML elements to extend Markdown's functiona... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/github-flavored-markdown-syntax-examples/</link>
                <guid isPermaLink="false">66d038a57d662cf201f5ec59</guid>
                
                    <category>
                        <![CDATA[ GitHub ]]>
                    </category>
                
                    <category>
                        <![CDATA[ markdown ]]>
                    </category>
                
                    <category>
                        <![CDATA[ syntax ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technical writing ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Rajdeep Singh ]]>
                </dc:creator>
                <pubDate>Thu, 11 Apr 2024 19:08:04 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/04/freecodecampl-github.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p><a target="_blank" href="https://en.wikipedia.org/wiki/Markdown">Markdown</a> is a lightweight, open-source, easy-to-read and easy-to-write method of formatting text that you can use as plain text in any IDE or editor.</p>
<p>When writing on GitHub, you can use Markdown syntax and HTML elements to extend Markdown's functionality. You can use Markdown syntax everywhere in GitHub, such as in the README file, wiki, comments, pull requests, and when creating issues.</p>
<p>For every software developer, learning markdown is an essential step along the path of your career.</p>
<p>To enhance Markdown's basic features, GitHub added some custom functionalities and created <a target="_blank" href="https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/about-writing-and-formatting-on-github">GitHub-Flavored Markdown</a>. With this, you can easily interact with other users in pull requests and issues by mentioning user, issue, and PR references and adding emoji.</p>
<p>This tutorial teaches you the basics of GitHub-Flavored Markdown so you can start using it in your projects.</p>
<p>All the code is <a target="_blank" href="https://github.com/officialrajdeepsingh/github-tutorial">available in the GitHub repository</a>.</p>
<h2 id="heading-github-flavored-markdown-syntax">GitHub-Flavored Markdown Syntax</h2>
<p>GitHub Flavored Markdown syntax is divided into two parts.</p>
<ol>
<li><a class="post-section-overview" href="#basis-formatting-syntax">Basic Formatting Syntax</a></li>
<li><a class="post-section-overview" href="#heading-advanced-formatting-syntax">Advanced Formatting Syntax</a></li>
</ol>
<p>We'll look at each one in detail below.</p>
<h3 id="heading-basic-formatting-syntax">Basic Formatting Syntax</h3>
<p>Basic formatting syntax applies to everyone. It contains fundamental essentials such as headings, code, images, quotes, links, and so on – things you'll need to know for writing.</p>
<ol>
<li><a class="post-section-overview" href="#heading-headings">Headings</a></li>
<li><a class="post-section-overview" href="#heading-paragraphs">Paragraphs</a></li>
<li><a class="post-section-overview" href="#comment">Comment</a></li>
<li><a class="post-section-overview" href="#heading-styling-text">Styling text</a></li>
<li><a class="post-section-overview" href="#heading-quotes">Quotes</a></li>
<li><a class="post-section-overview" href="#heading-code">Code</a></li>
<li><a class="post-section-overview" href="#heading-links">Links</a></li>
<li><a class="post-section-overview" href="#heading-images">Images</a></li>
<li><a class="post-section-overview" href="#heading-lists">Lists</a></li>
<li><a class="post-section-overview" href="#heading-mentioning-people-and-teams">Mentioning people and teams</a></li>
<li><a class="post-section-overview" href="#heading-referencing-issues-and-pull-requests">Referencing issues and pull requests</a></li>
<li><a class="post-section-overview" href="#using-emojis">Using emojis</a></li>
<li><a class="post-section-overview" href="#heading-footnotes">Footnotes</a></li>
<li><a class="post-section-overview" href="#heading-alerts">Alerts</a></li>
</ol>
<p>Note that the code samples mostly come from <a target="_blank" href="https://docs.github.com/en/get-started">GitHub's documentation</a>.</p>
<h3 id="heading-headings">Headings</h3>
<p>You can use the <code>#</code> symbol to create headings. One <code>#</code> creates an H1 heading, two create an H2 heading, and so on, like this:</p>
<pre><code class="lang-markdown"><span class="hljs-section"># A first-level heading</span>
<span class="hljs-section">## A second-level heading</span>
<span class="hljs-section">### A third-level heading</span>
<span class="hljs-section">#### A four-level heading</span>
<span class="hljs-section">##### A five-level heading</span>
<span class="hljs-section">###### A six-level heading</span>
</code></pre>
<h3 id="heading-paragraphs">Paragraphs</h3>
<p>To create paragraphs, you can use a blank line to separate one or more lines of text or paragraphs.</p>
<pre><code class="lang-markdown">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam est odio, commodo id diam sed, pulvinar sagittis tortor. Nam vestibulum purus eros. Sed congue, mi id pretium auctor, nibh augue iaculis arcu, eu tristique quam dolor at erat.

Quisque vel odio condimentum, mollis sem vitae, porta diam. Praesent ligula elit, condimentum eget ex sed, commodo sollicitudin sapien.


Proin volutpat faucibus nulla. Nullam eros sem, ultricies gravida nunc nec, dapibus posuere nisl. Nunc lacinia elementum turpis in pharetra. Aenean eu neque eros.
</code></pre>
<h3 id="heading-comments">Comments</h3>
<p>Comments are available in almost every programming language. They help developers write notes and add additional information to their code, helping other developers understand what's going on and how the code is working.</p>
<p>To add notes and additional information in Markdown, use the following syntax: <code>&lt;!--- Wrap text ---&gt;</code>.</p>
<p>Here's an example:</p>
<pre><code class="lang-markdown"><span class="xml"><span class="hljs-comment">&lt;!-- This content will not appear in the rendered Markdown --&gt;</span></span>
</code></pre>
<h3 id="heading-styling-text">Styling text</h3>
<p>You can apply basic styles to your text, such as bold, italic, strikethrough, subscript, or superscript, to improve readability and convey your point more clearly.</p>
<ol>
<li>For <strong>Bold</strong>, you can use the following syntax:  <code>**your text**</code></li>
<li>For <strong><em>italics</em></strong>, you can use the following syntax:  <code>*your text* or _your text_.</code></li>
<li>For <strong>strikethrough</strong>, you can use the following syntax: <code>~~your text~~</code></li>
<li>For <strong>subscript</strong>, you can use the following syntax:  <code>The subscript &lt;sub&gt; text &lt;/sub&gt; is here.</code></li>
<li>For <strong>superscript</strong>, you can use the following syntax:  <code>The superscript &lt;sup&gt; text &lt;/sup&gt; is here.</code></li>
</ol>
<pre><code class="lang-markdown"><span class="hljs-section">## Bold</span>

<span class="hljs-strong">**your text**</span>

<span class="hljs-section">## italics</span>

<span class="hljs-emphasis">*your text*</span>
<span class="hljs-emphasis">_your text_</span>

<span class="hljs-section">## strikethrough</span>

~~your text~~

<span class="hljs-section">## subscript</span>

The subscript <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">sub</span>&gt;</span></span> text <span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">sub</span>&gt;</span></span> is here.

<span class="hljs-section">## superscript</span>

The subscript <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">sup</span>&gt;</span></span> text <span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">sup</span>&gt;</span></span> is here.
</code></pre>
<h3 id="heading-quotes">Quotes</h3>
<p>A blockquote or quote is a sentence or paragraph formatted to let the reader know that you're quoting someone. To create a blockquote in Markdown, you can use the <code>&gt;</code> symbol.</p>
<pre><code class="lang-markdown"><span class="hljs-quote">&gt; Text that is a quote</span>
</code></pre>
<h3 id="heading-code">Code</h3>
<p>Markdown files support two types of code samples: <strong>inline</strong> and <strong>code block</strong>.</p>
<ol>
<li>To add a code block in a Markdown file, use the following syntax: <code>``` your code ``` </code>.</li>
<li>To add inline code to the Markdown file, use the following syntax: <code>`your code` </code>.</li>
</ol>
<pre><code class="lang-markdown"><span class="hljs-section">## Code Block</span>
</code></pre>
<p>// ES5 syntax
var multiply = function(x, y) {
  return x * y;
};</p>
<p>// ES6 arrow function
var multiply = (x, y) =&gt; { return x * y; };</p>
<p>// Or even simpler
var multiply = (x, y) =&gt; x * y;</p>
<pre><code>
## Inline code 

JavaScript provides three different value comparison operations: strict equality using <span class="hljs-string">`===`</span>, loose equality using <span class="hljs-string">`==`</span>, and the <span class="hljs-string">`Object.is()`</span> method.
</code></pre><p>To support code highlighting in a code block, you can add an optional language identifier after your triple backticks (like JavaScript in the example below):</p>
<pre><code class="lang-markdown"><span class="hljs-section">## Code Block</span>

<span class="hljs-code">```javascript

// ES5 syntax
var multiply = function(x, y) {
  return x * y;
};

// ES6 arrow function
var multiply = (x, y) =&gt; { return x * y; };

// Or even simpler
var multiply = (x, y) =&gt; x * y;</span>
</code></pre>
<pre><code>
### Links

A markdown file divides links into two categories: **inline** and **relative**.

#### Inline links

To create an inline link <span class="hljs-keyword">in</span> a Markdown file, wrap the link text <span class="hljs-keyword">in</span> brackets <span class="hljs-string">`[ ]`</span> followed immediately by the URL <span class="hljs-keyword">in</span> parentheses <span class="hljs-string">`( )`</span>.

<span class="hljs-string">``</span><span class="hljs-string">`markdown
This site was built using [GitHub Pages](https://pages.github.com/).</span>
</code></pre><h4 id="heading-relative-links">Relative links</h4>
<p>Relative links are defined similarly to inline links but they change in the <code>[]</code> section: the <code>[]</code> section contains the path of the file in your repository. </p>
<p>You use relative links to link two files: for example, to link the CONTRIBUTING file into the README file.</p>
<pre><code class="lang-markdown">[<span class="hljs-string">Contribution guidelines</span>](<span class="hljs-link">docs/CONTRIBUTING.md</span>)
</code></pre>
<p>Relative links starting with <code>/</code> will be relative to the repository root. You can use all relative link operands, such as <code>./</code> and <code>../.</code>:</p>
<pre><code class="lang-markdown">[<span class="hljs-string">Contribution guidelines</span>](<span class="hljs-link">../docs/CONTRIBUTING.md</span>)
</code></pre>
<h3 id="heading-images">Images</h3>
<p>To add an image in a markdown file, add a <code>!</code> and then wrap the alt text in <code>[]</code>. Then, wrap the image link with parentheses <code>()</code>.</p>
<p>It looks like this:</p>
<pre><code class="lang-markdown">![<span class="hljs-string">Markdown</span>](<span class="hljs-link">https://img.shields.io/badge/markdown-%23000000.svg?style=for-the-badge&amp;logo=markdown&amp;logoColor=white</span>)
</code></pre>
<h3 id="heading-lists">Lists</h3>
<p>A list helps record essential information in order, which can be vital for the reader and makes it easy for people to understand and find information. </p>
<p>Markdown files support three types of lists:</p>
<ol>
<li>Ordered list</li>
<li>Unordered list</li>
<li>Task list</li>
</ol>
<h4 id="heading-ordered-list">Ordered list</h4>
<p>The first type is an ordered list. To create an ordered list, start with numbers followed by periods.</p>
<pre><code class="lang-markdown"><span class="hljs-bullet">1.</span> one
<span class="hljs-bullet">2.</span> two
<span class="hljs-bullet">3.</span> three
<span class="hljs-bullet">4.</span> four
</code></pre>
<h4 id="heading-unordered-list">Unordered list</h4>
<p>The second type is an unordered list. To create an unordered list, use <code>-</code>, <code>+</code> or <code>*</code> (depending on your preference - they'll all render as an unordered list):</p>
<pre><code class="lang-markdown"><span class="hljs-bullet">*</span> First item
<span class="hljs-bullet">*</span> Second item
<span class="hljs-bullet">*</span> Third item
<span class="hljs-bullet">*</span> Fourth item


<span class="hljs-bullet">-</span> First item
<span class="hljs-bullet">-</span> Second item
<span class="hljs-bullet">-</span> Third item
<span class="hljs-bullet">-</span> Fourth item

<span class="hljs-bullet">+</span> First item
<span class="hljs-bullet">+</span> Second item
<span class="hljs-bullet">+</span> Third item
<span class="hljs-bullet">+</span> Fourth item
</code></pre>
<h4 id="heading-task-list">Task list</h4>
<p>The third type is a task list. To create a task list, list items start with a hyphen, followed by a space, followed by square brackets <code>[]</code>. You can use an <code>x</code> in the bracket <code>[x]</code> to mark a task as complete.</p>
<pre><code class="lang-markdown"><span class="hljs-bullet">-</span> [x] #739
<span class="hljs-bullet">-</span> [ ] https://github.com/octo-org/octo-repo/issues/740
<span class="hljs-bullet">-</span> [ ] Add delight to the experience when all tasks are complete :tada:
</code></pre>
<h3 id="heading-mentioning-people-and-teams">Mentioning people and teams</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/username-in-github.png" alt="Mention users and teams in the markdown" width="600" height="400" loading="lazy">
<em>Mentioning users and teams in markdown</em></p>
<p>To mention a person or team in a GitHub markdown file, type <code>@</code>  and write the username or team username.</p>
<pre><code class="lang-markdown"><span class="hljs-section">## person or individual username</span>

@officialrajdeepsingh, check out the following change.

<span class="hljs-section">## Team or company</span>
The section blog theme is maintained by @frontendweb
</code></pre>
<h3 id="heading-referencing-issues-and-pull-requests">Referencing issues and pull requests</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/tag-and-refrence-with-markdown.png" alt="Issues and pull request" width="600" height="400" loading="lazy">
<em>Issues and pull requests</em></p>
<p>To mention issues and pull requests in a GitHub markdown file, type a <code>#</code>, then type the issue or pull request number or title. Then press either tab or enter to complete the highlighted result.</p>
<pre><code class="lang-markdown">Remove the default <span class="hljs-emphasis">_target blank in logo #93</span>
</code></pre>
<h3 id="heading-using-emoji">Using emoji</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/emoji-in-markdown.png" alt="Adding emoji in markdown." width="600" height="400" loading="lazy">
<em>Adding emoji in markdown.</em></p>
<p>To add an emoji to your writing, type the emoji's code between two colons. If you just type <code>:</code>, a list of suggested emojis on GitHub will appear. </p>
<p>Once you find the emoji you're looking for, press Tab or Enter to choose the highlighted result.</p>
<pre><code class="lang-markdown">Don't forget to leave a star on our repository! :star:
</code></pre>
<h3 id="heading-footnotes">Footnotes</h3>
<p>To add a footnote reference, add a caret and an identifier inside brackets <code>([^1])</code> using the following syntax:</p>
<pre><code class="lang-markdown">Here's a simple footnote,[^1] and here's a longer one.[^bignote]

[<span class="hljs-symbol">^1</span>]: <span class="hljs-link">This is the first footnote.</span>

[<span class="hljs-symbol">^bignote</span>]: <span class="hljs-link">Here's one with multiple paragraphs and code.</span>
</code></pre>
<h3 id="heading-alerts">Alerts</h3>
<p>Alerts are a Markdown extension based on the block quote syntax that you can use to emphasize important information.</p>
<p>GitHub Flavored Markdown supports five types of alerts: <code>[!NOTE]</code>, <code>[!TIP]</code>, <code>[!IMPORTANT]</code>, <code>[!WARNING]</code>, and <code>[!CAUTION]</code>. You can use any of them:</p>
<pre><code class="lang-markdown"><span class="hljs-quote">&gt; [!NOTE]</span>
<span class="hljs-quote">&gt; Useful information that users should know, even when skimming content.</span>

<span class="hljs-quote">&gt; [!TIP]</span>
<span class="hljs-quote">&gt; Helpful advice for doing things better or more easily.</span>

<span class="hljs-quote">&gt; [!IMPORTANT]</span>
<span class="hljs-quote">&gt; Key information users need to know to achieve their goal.</span>

<span class="hljs-quote">&gt; [!WARNING]</span>
<span class="hljs-quote">&gt; Urgent info that needs immediate user attention to avoid problems.</span>

<span class="hljs-quote">&gt; [!CAUTION]</span>
<span class="hljs-quote">&gt; Advises about risks or negative outcomes of certain actions.</span>
</code></pre>
<p>The Alert syntax looks like this in the browser:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/alert.png" alt="Adding alert example in markdown." width="600" height="400" loading="lazy">
<em>Adding alert example in markdown.</em></p>
<h2 id="heading-advanced-formatting-syntax">Advanced Formatting Syntax</h2>
<p>This advanced formatting syntax section contains advanced use cases, such as adding diagrams and tables, collapsed sections, mathematical expressions, and more.</p>
<ol>
<li><a class="post-section-overview" href="#heading-creating-a-table">Creating a table</a></li>
<li><a class="post-section-overview" href="#heading-creating-a-collapsed-section">Creating a collapsed section</a></li>
<li><a class="post-section-overview" href="#heading-creating-diagrams">Creating diagrams</a></li>
<li><a class="post-section-overview" href="#heading-mathematical-expressions">Mathematical expressions</a></li>
</ol>
<h3 id="heading-creating-a-table">Creating a table</h3>
<p>To create tables in Markdown, you can use pipes <code>|</code> and hyphens <code>-</code>. Hyphens are used to create a column's header, while pipes are used to separate columns.</p>
<pre><code class="lang-markdown">| First Header  | Second Header |
| ------------- | ------------- |
| Content Cell  | Content Cell  |
| Content Cell  | Content Cell  |
</code></pre>
<p>The table looks like this in the browser:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/table-in-markdown.png" alt="Table example in markdown." width="600" height="400" loading="lazy">
<em>Table example in markdown.</em></p>
<h3 id="heading-creating-a-collapsed-section">Creating a collapsed section</h3>
<p>To create a collapsed section in a markdown file, you can use the <code>&lt;details&gt;</code> tag. This tag is an HTML element that you can easily use to extend the functionality of GitHub Flavored Markdown. Here's how it works:</p>
<pre><code class="lang-markdown"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">details</span>&gt;</span></span>
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">summary</span>&gt;</span></span>Click to here. <span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">summary</span>&gt;</span></span>

   ### You can add a message here

   You can add text within a collapsed section. 

   You can add an image or a code block, too.

   <span class="hljs-code">```ruby
     puts "Hello World"</span>
</code></pre>
<p></p>
<pre><code>
The collapsed syntax looks like <span class="hljs-built_in">this</span> <span class="hljs-keyword">in</span> the browser:

![Collapsed example <span class="hljs-keyword">in</span> markdown.](https:<span class="hljs-comment">//www.freecodecamp.org/news/content/images/2024/04/Collapsed-in-markdown.png)</span>
_Collapsed example <span class="hljs-keyword">in</span> markdown._

### Creating diagrams

To add diagrams to a Markdown file, use triple backticks and wrap them inside quadruple backticks. Then, tell which identifier (Mermaid, GeoJSON, TopJSON, ASCII STL) you used <span class="hljs-keyword">for</span> the diagram.

GitHub supports diagrams using four syntaxes: mermaid, geoJSON, topoJSON, and ASCII STL.

<span class="hljs-number">1.</span> [Mermaid](#heading-mermaid) 
<span class="hljs-number">2.</span> [GeoJSON and TopoJSON](#heading-geojson-and-topojson)
<span class="hljs-number">3.</span> [ASCII STL](#heading-ascii-stl)

#### Mermaid 

[Mermaid](https:<span class="hljs-comment">//mermaid.js.org) is a Markdown-inspired tool that renders text into diagrams. You can create flow charts, sequence diagrams, pie charts, and more with Mermaid.</span>

The GitHub-flavored Markdown has extended the functionality <span class="hljs-keyword">of</span> using Mermaid <span class="hljs-keyword">with</span> Markdown.

You can create flow charts, sequence diagrams, pie charts, and so on inside Markdown. GitHub handles the rest <span class="hljs-keyword">of</span> that. So how <span class="hljs-keyword">do</span> you render diagrams on the screen?

<span class="hljs-string">``</span><span class="hljs-string">`markdown
`</span><span class="hljs-string">``</span>mermaid
graph LR;
   A --  and --&gt; B -- to --&gt; C
</code></pre><pre><code>
The mermaid syntax looks like <span class="hljs-built_in">this</span> <span class="hljs-keyword">in</span> the browser.

![Mermaid example <span class="hljs-keyword">in</span> markdown.](https:<span class="hljs-comment">//www.freecodecamp.org/news/content/images/2024/04/mermaid-degram.png)</span>
_Mermaid example <span class="hljs-keyword">in</span> markdown._

#### GeoJSON and TopoJSON

You can use [GeoJSON](https:<span class="hljs-comment">//geojson.org/) or [TopoJSON](https://github.com/topojson/topojson) to add an interactive map to a GitHub repository in a README file or GitHub Wiki.</span>

You can use code block syntax to add an interactive map.

<span class="hljs-number">1.</span> GeoJSON can create a map by specifying coordinates. To add an interactive map, use the following syntax:  <span class="hljs-string">` `</span><span class="hljs-string">``</span>geojson  your code <span class="hljs-string">``</span><span class="hljs-string">` `</span>
<span class="hljs-number">2.</span> TopoJSON can create a map by specifying coordinates and shapes. To add an interactive map, use the following syntax: <span class="hljs-string">` `</span><span class="hljs-string">``</span>topojson  your code <span class="hljs-string">``</span><span class="hljs-string">` `</span>

**Example using GeoJSON:**

<span class="hljs-string">``</span><span class="hljs-string">`markdown
`</span><span class="hljs-string">``</span>geojson
{
  <span class="hljs-string">"type"</span>: <span class="hljs-string">"FeatureCollection"</span>,
  <span class="hljs-string">"features"</span>: [
    {
      <span class="hljs-string">"type"</span>: <span class="hljs-string">"Feature"</span>,
      <span class="hljs-string">"id"</span>: <span class="hljs-number">1</span>,
      <span class="hljs-string">"properties"</span>: {
        <span class="hljs-string">"ID"</span>: <span class="hljs-number">0</span>
      },
      <span class="hljs-string">"geometry"</span>: {
        <span class="hljs-string">"type"</span>: <span class="hljs-string">"Polygon"</span>,
        <span class="hljs-string">"coordinates"</span>: [
          [
              [<span class="hljs-number">-90</span>,<span class="hljs-number">35</span>],
              [<span class="hljs-number">-90</span>,<span class="hljs-number">30</span>],
              [<span class="hljs-number">-85</span>,<span class="hljs-number">30</span>],
              [<span class="hljs-number">-85</span>,<span class="hljs-number">35</span>],
              [<span class="hljs-number">-90</span>,<span class="hljs-number">35</span>]
          ]
        ]
      }
    }
  ]
}
</code></pre><pre><code>
**Example <span class="hljs-keyword">of</span> TopJSON:**

<span class="hljs-string">``</span><span class="hljs-string">`markdown
`</span><span class="hljs-string">``</span>topojson
{
  <span class="hljs-string">"type"</span>: <span class="hljs-string">"Topology"</span>,
  <span class="hljs-string">"transform"</span>: {
    <span class="hljs-string">"scale"</span>: [<span class="hljs-number">0.0005000500050005</span>, <span class="hljs-number">0.00010001000100010001</span>],
    <span class="hljs-string">"translate"</span>: [<span class="hljs-number">100</span>, <span class="hljs-number">0</span>]
  },
  <span class="hljs-string">"objects"</span>: {
    <span class="hljs-string">"example"</span>: {
      <span class="hljs-string">"type"</span>: <span class="hljs-string">"GeometryCollection"</span>,
      <span class="hljs-string">"geometries"</span>: [
        {
          <span class="hljs-string">"type"</span>: <span class="hljs-string">"Point"</span>,
          <span class="hljs-string">"properties"</span>: {<span class="hljs-string">"prop0"</span>: <span class="hljs-string">"value0"</span>},
          <span class="hljs-string">"coordinates"</span>: [<span class="hljs-number">4000</span>, <span class="hljs-number">5000</span>]
        },
        {
          <span class="hljs-string">"type"</span>: <span class="hljs-string">"LineString"</span>,
          <span class="hljs-string">"properties"</span>: {<span class="hljs-string">"prop0"</span>: <span class="hljs-string">"value0"</span>, <span class="hljs-string">"prop1"</span>: <span class="hljs-number">0</span>},
          <span class="hljs-string">"arcs"</span>: [<span class="hljs-number">0</span>]
        },
        {
          <span class="hljs-string">"type"</span>: <span class="hljs-string">"Polygon"</span>,
          <span class="hljs-string">"properties"</span>: {<span class="hljs-string">"prop0"</span>: <span class="hljs-string">"value0"</span>,
            <span class="hljs-string">"prop1"</span>: {<span class="hljs-string">"this"</span>: <span class="hljs-string">"that"</span>}
          },
          <span class="hljs-string">"arcs"</span>: [[<span class="hljs-number">1</span>]]
        }
      ]
    }
  },
  <span class="hljs-string">"arcs"</span>: [[[<span class="hljs-number">4000</span>, <span class="hljs-number">0</span>], [<span class="hljs-number">1999</span>, <span class="hljs-number">9999</span>], [<span class="hljs-number">2000</span>, <span class="hljs-number">-9999</span>], [<span class="hljs-number">2000</span>, <span class="hljs-number">9999</span>]],[[<span class="hljs-number">0</span>, <span class="hljs-number">0</span>], [<span class="hljs-number">0</span>, <span class="hljs-number">9999</span>], [<span class="hljs-number">2000</span>, <span class="hljs-number">0</span>], [<span class="hljs-number">0</span>, <span class="hljs-number">-9999</span>], [<span class="hljs-number">-2000</span>, <span class="hljs-number">0</span>]]]
}
</code></pre><pre><code>
### ASCII STL

GitHub Flavored Markdown supports STL syntax. STL syntax allows you to add interactive <span class="hljs-number">3</span>D models <span class="hljs-keyword">in</span> markdown. You can use the following syntax: <span class="hljs-string">` `</span><span class="hljs-string">``</span>stl your code.<span class="hljs-string">``</span><span class="hljs-string">` `</span>

<span class="hljs-string">``</span><span class="hljs-string">`markdown
`</span><span class="hljs-string">``</span>stl
solid cube_corner
  facet normal <span class="hljs-number">0.0</span> <span class="hljs-number">-1.0</span> <span class="hljs-number">0.0</span>
    outer loop
      vertex <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span>
      vertex <span class="hljs-number">1.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span>
      vertex <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">1.0</span>
    endloop
  endfacet
  facet normal <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">-1.0</span>
    outer loop
      vertex <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span>
      vertex <span class="hljs-number">0.0</span> <span class="hljs-number">1.0</span> <span class="hljs-number">0.0</span>
      vertex <span class="hljs-number">1.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span>
    endloop
  endfacet
  facet normal <span class="hljs-number">-1.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span>
    outer loop
      vertex <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span>
      vertex <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">1.0</span>
      vertex <span class="hljs-number">0.0</span> <span class="hljs-number">1.0</span> <span class="hljs-number">0.0</span>
    endloop
  endfacet
  facet normal <span class="hljs-number">0.577</span> <span class="hljs-number">0.577</span> <span class="hljs-number">0.577</span>
    outer loop
      vertex <span class="hljs-number">1.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span>
      vertex <span class="hljs-number">0.0</span> <span class="hljs-number">1.0</span> <span class="hljs-number">0.0</span>
      vertex <span class="hljs-number">0.0</span> <span class="hljs-number">0.0</span> <span class="hljs-number">1.0</span>
    endloop
  endfacet
endsolid
</code></pre><pre><code>
The STL syntax looks like <span class="hljs-built_in">this</span> <span class="hljs-keyword">in</span> the browser:

![STL example <span class="hljs-keyword">in</span> markdown.](https:<span class="hljs-comment">//www.freecodecamp.org/news/content/images/2024/04/stl-example.png)</span>
_STL example <span class="hljs-keyword">in</span> markdown._

### Mathematical expressions

You can add mathematical expressions, such <span class="hljs-keyword">as</span> equations, terms, formulas, and so on, to a GitHub markdown file. GitHub uses [LaTeX](https:<span class="hljs-comment">//www.cmor-faculty.rice.edu/~heinken/latex/symbols.pdf) formatted within Markdown. There are two ways to add these expressions:</span>

<span class="hljs-number">1.</span> Writing inline math expressions
<span class="hljs-number">2.</span> Writing math expressions <span class="hljs-keyword">as</span> code blocks

#### Writing inline math expressions

An inline math expression starts <span class="hljs-keyword">with</span> <span class="hljs-string">`$`</span> and ends <span class="hljs-keyword">with</span> <span class="hljs-string">`$`</span>. 

<span class="hljs-string">``</span><span class="hljs-string">`markdown
Inline math expression example: $\sqrt{3x-1}+(1+x)^2$</span>
</code></pre><p>The inline math syntax looks like this in the browser:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/math-exp.png" alt="Inline math expression example" width="600" height="400" loading="lazy">
<em>Inline math expression example</em></p>
<h4 id="heading-writing-math-expressions-as-code-blocks">Writing math expressions as code blocks</h4>
<p>To add a math expression's code block to the Markdown file, use the <code>```math</code> code block and wrap it inside <code>``` </code> backticks to display the expression as a block.</p>
<p>To add a math expression's code block to the Markdown file, use the ````math code block and wrap it inside triple backticks to display the expression as a block.</p>
<pre><code class="lang-markdown"><span class="hljs-code">```math
\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)</span>
</code></pre>
<p>```</p>
<p>The math code block syntax looks like this in the browser:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/math-expre-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Code block math expression example</em></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Markdown syntax works well in GitHub and all other central Git servers, such as GitLab, Gitea, and so on.</p>
<p>Different tools name their markdown differently. For example, GitHub extends markdown functionality in its own way and builds GitHub Flavored Markdown. GitLab also extends markdown functionality and builds and creates a GitLab-flavored markdown.</p>
<p>Markdown syntax is mostly the same in every Git service. But alerts, diagrams, and a few other features only work in GitHub Flavored Markdown.</p>
<h2 id="heading-reference">Reference</h2>
<ul>
<li>GitHub docs – <a target="_blank" href="https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/quickstart-for-writing-on-github">quickstart for writing on GitHub</a></li>
<li>GitHub docs  – <a target="_blank" href="https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax">basic syntax</a></li>
<li>Tutorial about <a target="_blank" href="https://www.vanderveer.io/github-markdown-render-stl/">rendering STL in Markdown on GitHub</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What are BNF and EBNF in Programming? ]]>
                </title>
                <description>
                    <![CDATA[ As programmers, we communicate with computers through many languages: Python, JavaScript, SQL, C... you name it. But do you know how the creators of these languages precisely describe their syntax to us, leaving no room for doubt? They could've relie... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-are-bnf-and-ebnf/</link>
                <guid isPermaLink="false">66c5f74ffdf18f48a8c0c35f</guid>
                
                    <category>
                        <![CDATA[ programming languages ]]>
                    </category>
                
                    <category>
                        <![CDATA[ syntax ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ashutosh Biswas ]]>
                </dc:creator>
                <pubDate>Mon, 17 Jul 2023 17:26:21 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/07/ryan-wallace-azA1hLbjBBo-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>As programmers, we communicate with computers through many languages: Python, JavaScript, SQL, C... you name it. But do you know how the creators of these languages precisely describe their syntax to us, leaving no room for doubt?</p>
<p>They could've relied on plain English, but that would not be a good solution because of the potential verbosity and ambiguity. So they used specially designed languages for it. </p>
<p>In this article, you'll learn about two of these widely used languages: BNF and EBNF.</p>
<p>Another fascinating aspect of these special languages or notations is that you can write the grammar of your own language using them and give it as input to some magical computer programs called "parser generators". These can output other programs capable of parsing any text according to the grammar you used. How amazing is that? </p>
<p>This feature can save you a lot of time since manually writing such programs is challenging and time-consuming.</p>
<p>Before learning (E)BNF, it's helpful to be able to distinguish between syntax and semantics. So let's start from there.</p>
<h2 id="heading-syntax-vs-semantics-in-programming-languages">Syntax vs Semantics in Programming Languages</h2>
<p>Syntax refers to the structure of the elements of a language based on its type. On the other hand, semantics are all about the meaning.</p>
<p>Something written syntactically correctly in a language can be completely meaningless. And no text can be meaningful if its syntax is incorrect.</p>
<p>Two of the most famous sentences regarding syntax and semantics are <a target="_blank" href="https://en.wikipedia.org/wiki/Colorless_green_ideas_sleep_furiously">composed by Noam Chomsky</a>:</p>
<ol>
<li>Colorless green ideas sleep furiously.</li>
<li>Furiously sleep ideas green colorless.</li>
</ol>
<p>The first sentence's syntax is correct but it's meaningless. And since the second one is syntactically wrong, it is far from being meaningful.</p>
<p>The same is true for programming languages too. Let's look at the following two JavaScript code snippets to see what I mean.</p>
<p>The following code is syntactically correct but semantically wrong because it's not possible to reassign something to a constant variable:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> name = <span class="hljs-string">"Palash"</span>;
name = <span class="hljs-string">"Akash"</span>;
</code></pre>
<p>The following is syntactically incorrect and thus does not even have any chance to be semantically correct.</p>
<pre><code class="lang-js"><span class="hljs-string">"Palash"</span> = <span class="hljs-keyword">const</span> name;
<span class="hljs-string">"Akash"</span> = name;
</code></pre>
<p>You check the syntax of your JavaScript code online with a tool like the <a target="_blank" href="https://esprima.org/demo/validate.html">Esprima Syntax Validator</a>.</p>
<p>There are two more concepts you need to understand before learning to read BNF/EBNF.</p>
<h2 id="heading-terminals-and-non-terminals">Terminals and Non-Terminals</h2>
<p>BNF/EBNF is usually used to specify the grammar of a language. Grammar is a set of <em>rules</em> (also called <em>production rules</em>). Here language refers to nothing but a set of strings that are valid according to the rules of its grammar.</p>
<p>A BNF/EBNF grammar description is an unordered list of rules. <em>Rules</em> are used to define <em>symbols</em> with the help of other symbols.</p>
<p>You can think of <em>symbols</em> as the building blocks of grammar. There are two kinds of symbols:</p>
<ul>
<li><strong>Terminal (or Terminal symbol)</strong>: Terminals are strings written within quotes. They are meant to be used as they are. Nothing is hidden behind them. For example <code>"freeCodeCamp"</code> or <code>"firefly"</code>.</li>
<li><strong>Non-terminal (or Non-terminal symbol)</strong>: Sometimes we need a name to refer to something else. These are called <em>non-terminals</em>. In BNF, <em>non-terminal</em> names are written within angle brackets (for example <code>&lt;statement&gt;</code>), while in EBNF they don't usually use brackets (for example <code>statement</code>).</li>
</ul>
<p>The whole language is derived from a single <em>non-terminal</em> symbol. This is called the <strong>start</strong> or <strong>root</strong> <strong>symbol</strong> of the grammar. By convention, it is written as the first non-terminal in the BNF/EBNF grammar description.</p>
<p>Finally, you are ready to learn BNF. It's easier than you might think it is.</p>
<h2 id="heading-what-is-bnf">What is BNF?</h2>
<p>BNF stands for <strong>B</strong>ackus–<strong>N</strong>aur <strong>F</strong>orm which resulted primarily from the contributions of <a target="_blank" href="https://en.wikipedia.org/wiki/John_Backus">John Backus</a> and <a target="_blank" href="https://en.wikipedia.org/wiki/Peter_Naur">Peter Naur</a>.</p>
<p>The syntax of BNF/EBNF is so simple that many people adopted their styles. So in different places, you will most likely see different styles. If the syntax is different from conventional ones, that's usually documented there. In this article I will use one particular style, just to keep things simple.</p>
<p>Below is an example of a simple <em>production rule</em> in BNF:</p>
<pre><code class="lang-bnf">&lt;something&gt; ::= "content"
</code></pre>
<p>Each rule in BNF (also in ENBF) has three parts:</p>
<ul>
<li><strong>Left-hand side</strong>: Here we write a non-terminal to define it. In the above example, it is <code>&lt;something&gt;</code>.</li>
<li><strong><code>::=</code></strong>: This character group separates the <strong>Left hand side</strong> from <strong>Right hand side</strong>. Read this symbol as "is defined as".</li>
<li><strong>Right-hand side</strong>: The definition of the non-terminal specified on the right-hand side. In the above example, it's <code>"content"</code>.</li>
</ul>
<p>The above <code>&lt;something&gt;</code> is just one thing fixed thing. Let's now see all the ways you can compose a <em>non-terminal</em>.</p>
<h3 id="heading-how-to-compose-a-non-terminal">How to compose a non-terminal</h3>
<p>BNF offers two methods to us:</p>
<ul>
<li>Sequencing</li>
<li>Choice</li>
</ul>
<p>You can just write a combination of one or more terminals or non-terminals in a sequence and the result is their concatenation, with non-terminals being replaced by their content. For example, you can express your breakfast in the following ways:</p>
<pre><code class="lang-bnf">&lt;breakfast&gt; ::= &lt;drink&gt; " and biscuit"
&lt;drink&gt; ::= "tea"
</code></pre>
<p>It means the only option for breakfast for you is <code>"tea and biscuit"</code>. Note that here, the order of symbols is important.</p>
<p>Let's say someday you want to drink coffee instead of tea. In this case, you can express your possible breakfast items like below:</p>
<pre><code class="lang-bnf">&lt;breakfast&gt; ::= &lt;drink&gt; " and biscuit"
&lt;drink&gt; ::= "tea" | "coffee"
</code></pre>
<p>The <code>|</code> operator indicates that the parts separated by it are choices. Which means the non-terminal on the left can be any such part. Here the order is <em>unimportant</em>, that is there is no difference between <code>"tea" | "coffee</code> and <code>"coffee" | "tea"</code>.</p>
<p>That is really all you need to know about BNF to read and understand it and even express the syntax of your own language using it. Believe it or not, it's that simple. And yet it can be used to describe the syntax of many programming languages and other kinds of coding languages.</p>
<p>The thing that makes it possible to break down complex syntax programming languages easily is the ability to define non-terminal symbols recursively. </p>
<p>As a simple example let's see how you express one or more digits in BNF:</p>
<pre><code class="lang-bnf">&lt;digits&gt; ::= &lt;digit&gt; | &lt;digit&gt; &lt;digits&gt;
&lt;digit&gt; ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
</code></pre>
<p>If you want to see a simple real-world example of BNF grammar checkout: <a target="_blank" href="https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions">Semver notation</a>.</p>
<h2 id="heading-what-is-ebnf">What is EBNF?</h2>
<p>BNF is fine, but sometimes it can become verbose and hard to interpret. EBNF (which stands for <strong>E</strong>xtended <strong>B</strong>ackus–<strong>N</strong>aur <strong>F</strong>orm) may help you in those cases. For example, the previous example can be written in EBNF like below:</p>
<pre><code class="lang-ebnf">digits = digit { digit }
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
</code></pre>
<p>The braces above mean that its inner part may be repeated 0 or more times. It frees your mind from getting lost in recursion.</p>
<p>One interesting fact is that everything you can express in EBNF can also be expressed in BNF.</p>
<p>EBNF usually uses a slightly different notation than BNF. For example:</p>
<ul>
<li><code>::=</code> becomes just <code>=</code>.</li>
<li>There are no angle brackets around non-terminals.</li>
</ul>
<pre><code class="lang-ad-info">For concatenation, instead of juxtaposition, some prefer `,` to be more explicit. However, I will not use it here.
</code></pre>
<p>Don't assume that these styles to be universal. There are several variants of them and they are usually clear from the context. The more important thing to focus on is the new operations it offers like the braces we've seen above.</p>
<p>EBNF extends BNF by adding the following 3 operations:</p>
<ul>
<li>Option</li>
<li>Repetition</li>
<li>Grouping</li>
</ul>
<h3 id="heading-option">Option</h3>
<p>Option uses square brackets to make the inner content optional. Example:</p>
<pre><code class="lang-ebnf">thing = "water" [ "melon" ]
</code></pre>
<p>So the above <code>thing</code> is either <code>water</code> or <code>watermelon</code>.</p>
<h3 id="heading-repetition">Repetition</h3>
<p>Curly braces indicate the inner content may be repeated 0 or more times. You have already seen a good example of it above. Below is a very simple one just to make the idea solid in your mind:</p>
<pre><code class="lang-ebnf">long_google = "Goo" { "o" } "gle"
</code></pre>
<p>So <code>"Google"</code>, <code>"Gooogle"</code>, <code>"Gooooooogle"</code> are all valid <code>long_google</code> non-terminal.</p>
<h3 id="heading-grouping">Grouping</h3>
<p>Parentheses can be used to indicate grouping. It means everything they wrap can be replaced with any of the valid strings that the contents of the group represent according to the rules of EBNF. For example:</p>
<pre><code class="lang-ebnf">fly = ("fire" | "fruit") "fly"
</code></pre>
<p>Here  <code>fly</code> is either <code>"firefly"</code> or <code>"fruitfly"</code>.</p>
<p>With BNF we could not do that in one line. It would look like the following in BNF:</p>
<pre><code class="lang-ebnf">&lt;fly&gt; ::= &lt;type&gt; "fly"
&lt;type&gt; ::= "fire" | "fruit"
</code></pre>
<h2 id="heading-the-bnf-playground">The BNF Playground</h2>
<p>There is a very nice online playground for BNF and EBNF: <a target="_blank" href="https://bnfplayground.pauliankline.com/"> Playground</a>.</p>
<p>I recommend you check it out and play with it. It uses a slightly different notation so read the "Grammar Help" section beforehand.</p>
<p>It can test if a string is valid according to the grammar you entered. It can also generate random strings based on your grammar!</p>
<p>For fun this is the syntax of a poem-like text (credit goes to chatGPT):</p>
<pre><code class="lang-ebnf">&lt;poem&gt; ::= &lt;line&gt; | &lt;line&gt; "\n" &lt;poem&gt;
&lt;line&gt; ::= &lt;noun_phrase&gt; " " &lt;verb_phrase&gt; " " &lt;adjective&gt;
&lt;noun_phrase&gt; ::= "the " &lt;adjective&gt; " " &lt;noun&gt; | &lt;noun&gt;
&lt;verb_phrase&gt; ::= &lt;verb&gt; | &lt;verb&gt; " " &lt;adverb&gt;
&lt;adjective&gt; ::= "red" | "blue" | "green" | "yellow"
&lt;noun&gt; ::= "sky" | "sun" | "grass" | "flower"
&lt;verb&gt; ::= "shines" | "glows" | "grows" | "blooms"
&lt;adverb&gt; ::= "brightly" | "slowly" | "vividly" | "peacefully"
</code></pre>
<p>Go ahead and copy-paste it into the playground and press the "Generate Random" button to get some mostly meaningless lines of a grammatically correct poem.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>BNF and EBNF are simple and powerful notations to write what computer scientists call <em>context-free grammar</em>. </p>
<p>In simple terms it means the expansion of a non-terminal is not dependent on the context (surrounding symbols), that is it's context-free. It is the most widely used grammar form to formalize the syntax of coding languages.</p>
<p>Here are some resources you might find interesting:</p>
<ul>
<li><a target="_blank" href="https://tomassetti.me/ebnf/">EBNF: How to Describe the Grammar of a Language</a></li>
<li><a target="_blank" href="https://matt.might.net/articles/grammars-bnf-ebnf/">The language of languages</a></li>
<li>Parser generators:<ul>
<li><a target="_blank" href="https://www.antlr.org/">ANTLR</a>, a very powerful parser generator capable of writing parsers in many languages.</li>
<li>If you are a JavaScript person like me and want to get started with a parser generator, take a look at <a target="_blank" href="https://nearley.js.org/">nearly.js</a> for a gentle start.</li>
</ul>
</li>
</ul>
<p>Below are some real-world grammars written using BNF/EBNF or similar notations that you might find interesting:</p>
<ul>
<li><a target="_blank" href="https://iamwilhelm.github.io/bnf-examples/lisp">Lisp</a></li>
<li><a target="_blank" href="https://www.lua.org/manual/5.4/manual.html#9">Lua</a></li>
<li><a target="_blank" href="https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions">Semver</a></li>
<li><a target="_blank" href="https://tc39.es/ecma262/multipage/grammar-summary.html#sec-grammar-summary">JavaScript</a></li>
<li><a target="_blank" href="https://facebook.github.io/jsx/">JSX</a></li>
<li><a target="_blank" href="https://docs.python.org/3/reference/grammar.html">Python</a></li>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/Value_definition_syntax">Value Definition Syntax in CSS</a></li>
</ul>
<p>Thanks for reading. Let me know on <a target="_blank" href="https://twitter.com/ashutoshbw">Twitter</a> if you have any questions or found this article helpful. Happy learning!</p>
<p>Photo by <a target="_blank" href="https://unsplash.com/@accrualbowtie?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ryan Wallace</a> on <a target="_blank" href="https://unsplash.com/photos/azA1hLbjBBo?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Statement vs Expression – What's the Difference in Programming? ]]>
                </title>
                <description>
                    <![CDATA[ By Ogundiran Ayobami Learning the syntax of a programming language is key if you want to use that language effectively. This is true for both new and experienced developers. And one of the most important things to pay attention to while learning a pr... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/statement-vs-expression-whats-the-difference-in-programming/</link>
                <guid isPermaLink="false">66d84e747211ea6be29e1b49</guid>
                
                    <category>
                        <![CDATA[ beginner ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ self-improvement  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ syntax ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tutorial ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 08 Dec 2022 23:44:58 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/12/kaleidico-7lryofJ0H9s-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ogundiran Ayobami</p>
<p>Learning the syntax of a programming language is key if you want to use that language effectively. This is true for both new and experienced developers.</p>
<p>And one of the most important things to pay attention to while learning a programming language is whether the code you're dealing with is a statement or an expression.</p>
<p>It can sometimes be confusing to differentiate between statements and expressions in programming. So this article is meant to simplify the differences so that you can improve your programming skills and become a better developer.</p>
<h2 id="heading-what-is-an-expression-in-programming">What is an Expression in Programming?</h2>
<p><img src="https://images.unsplash.com/photo-1603792907191-89e55f70099a?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDF8fHN1cnByaXNlZHxlbnwwfHx8fDE2NzA1MTMyNzI&amp;ixlib=rb-4.0.3&amp;q=80&amp;w=2000" alt="Senior caucasian man holding blank empty banner covering mouth with hand, shocked and afraid for mistake. surprised expression " width="2000" height="1333" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/@krakenimages?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit"&gt;krakenimages / &lt;a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm<em>campaign=api-credit)</em></p>
<p>An expression is any word or group of words or symbols that is a value. In programming, an expression is a value, or anything that executes and ends up being a value.</p>
<p>It is necessary to understand that a value is unique. For example, <code>const</code>, <code>let</code>, <code>2</code>, <code>4</code>, <code>s</code>, <code>a</code>, <code>true</code>, <code>false</code>, and <code>world</code> are values because each of them is unique in meaning or character.</p>
<p>Let's look at some code as an example:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> price = <span class="hljs-number">500</span>;
</code></pre>
<p>Judging from the code above, <code>const</code>, <code>price</code>, <code>=</code>, and <code>500</code> are expressions because each of them has a definite and unique meaning or value. But if we take all of them together <code>const price = 500</code> - then we have a statement.</p>
<p>Let's look at another example:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> multiply = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">firstNumber, secondNumber</span>) </span>{
    <span class="hljs-keyword">return</span> firstNumber * secondNumber;
}
</code></pre>
<p>Looking at the code above, you can see an anonymous function is assigned to a variable. Oh, wait! You might know that any function is a statement. Can it also be an expression? </p>
<p>Yes! A "function" and a "class" are both statements and expressions because they can perform actions (do or not do tasks) and still execute to a value.</p>
<p>This brings us to statements – so what are they?</p>
<h2 id="heading-what-is-a-statement-in-programming">What is a Statement in Programming?</h2>
<p>A statement is a group of expressions and/or statements that you design to carry out a task or an action. </p>
<p>Statements are two-sided – that is, they either do tasks or don't do them. Any statement that can return a value is automatically qualified to be used as an expression. That is why a function or class is a statement and also an expression in JavaScript.</p>
<p>If you look at the example of the function under the section on expressions, you can see it is assigned and execute to a value passed to a variable. That is why it is an expression in that case.</p>
<h2 id="heading-examples-of-statements-in-programming">Examples of Statements in Programming</h2>
<h3 id="heading-inline-statements">Inline statements</h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> amount = $<span class="hljs-number">2000</span>;
</code></pre>
<p>The whole of the code above is a statement because it carries out the task of assigning <code>$2000</code> to <code>amount</code>. It is safe to say a line of code is a statement because most compilers or interpreters don't execute any standalone expression.</p>
<p><img src="https://images.unsplash.com/photo-1625314517201-dd442445cf42?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDF8fGV4Y2l0ZWR8ZW58MHx8fHwxNjcwNTEzMzMx&amp;ixlib=rb-4.0.3&amp;q=80&amp;w=2000" alt="Happy man portraits " width="2000" height="1333" loading="lazy">
<em>Photo by [Unsplash](https://unsplash.com/@1nimidiffa</em>?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit"&gt;Nimi Diffa / &lt;a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm<em>campaign=api-credit)</em></p>
<h3 id="heading-block-statements">Block statements</h3>
<p>Look at the below <code>if</code> statement:</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span>( iLoveYou ) {
    <span class="hljs-keyword">let</span> status = <span class="hljs-string">"you should know I mean it"</span>; 

    <span class="hljs-built_in">console</span>.log(status)
}
</code></pre>
<p>The <code>if statement</code> is a statement because it helps us check whether <code>I love you</code> or not. As I have said before, it is two-sided: this code finds out whether "I love you" or not, and that is why it is a statement. Also, it doesn't return any value but it can create side effects.</p>
<p>Here's a <code>loop</code> statement:</p>
<pre><code class="lang-js"><span class="hljs-keyword">for</span>( ) {
   <span class="hljs-comment">//code block</span>
}

<span class="hljs-keyword">while</span> ( counter &lt; <span class="hljs-number">5</span> ) {
   <span class="hljs-built_in">console</span>.log(<span class="hljs-string">' less than 5'</span> );
}
</code></pre>
<p>In short, any loop is a statement because if it can only do the tasks it is meant to do or not – does loop and doesn't loop. But a loop can't execute to a value in the end. They can only have side effects in JavaScript. Once they can execute to a value in a programming language, then they can also be used as an expression.</p>
<p>For example, you can use forloop and if statement as expressions in Python.</p>
<pre><code class="lang-python"><span class="hljs-comment"># Define a list of numbers</span>
numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]

<span class="hljs-comment"># compute the sum of the numbers</span>
total = sum([num <span class="hljs-keyword">for</span> num <span class="hljs-keyword">in</span> numbers])
</code></pre>
<p>There is also an "IF" expression in Python. That means that something that is a statement in one language can be an expression (or both statement and expression) in another.</p>
<pre><code class="lang-python">a = <span class="hljs-number">1</span>
result = <span class="hljs-string">'even'</span> <span class="hljs-keyword">if</span> a % <span class="hljs-number">2</span> == <span class="hljs-number">0</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'odd'</span>
print(result)
</code></pre>
<p>Look at the below function statement:</p>
<pre><code class="lang-js"><span class="hljs-comment">//we define the function as a statement</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">firstNumber, secondNumber</span>) </span>{
    <span class="hljs-keyword">return</span> firstNumber * secondNumber;
}

<span class="hljs-comment">//we call it as a statement</span>
add(<span class="hljs-number">2</span>, <span class="hljs-number">3</span>);
</code></pre>
<p>We declare the function <code>add(firstNumber, secondNumber)</code> and it returns a value. The function is called with two arguments as in <code>add(2, 3)</code> by declaration and so it is a statement. If you pay close attention, you will realize that calling the function as a statement is useless since it has no side effect.</p>
<p>Hey, stop! How can we turn it into an expression? Oh yeah, we can do it like this:</p>
<pre><code class="lang-js">   <span class="hljs-keyword">const</span> five = add(<span class="hljs-number">2</span>, <span class="hljs-number">3</span>)
</code></pre>
<p>Though the function is now an expression the way it is called above, the whole of the code is still a statement.</p>
<p>Check out this class statement:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> User = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span> </span>{
  sayHi() {
    alert(<span class="hljs-string">"Hi"</span>);
  }
};
</code></pre>
<p>You can see that we declare the class "Person" and <strong>instantiate and assign</strong> it to "User" immediately. So, it is used as an expression. </p>
<p>Now, let's use it as a statement:</p>
<pre><code class="lang-js"><span class="hljs-comment">//We write class as a statement</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span> </span>{
  sayHi() {
    alert(<span class="hljs-string">"Hi"</span>);
  }
}

<span class="hljs-comment">// we instantiate it as a statement.</span>
<span class="hljs-keyword">new</span> Person().sayHi();

<span class="hljs-comment">// we instantiate it as an expression</span>
<span class="hljs-keyword">let</span> User = Person();
</code></pre>
<p><a target="_blank" href="https://www.techtarget.com/whatis/definition/class#:~:text=In%20object-oriented%20programming%20%2C%20a,ideas%20of%20object-oriented%20programming.">A class</a> is similar to a function in the sense that it can be declared, assigned, or used as an operand just like a class. So, a class is a statement and/or an expression.</p>
<h2 id="heading-the-main-differences-between-an-expression-and-a-statement-in-programming">The Main Differences Between an Expression and a Statement in Programming</h2>
<p>Expressions can be assigned or used as operands, while statements can only be declared.</p>
<p>Statements create side effects to be useful, while expressions are values or execute to values.</p>
<p>Expressions are unique in meaning, while statements are two-sided in execution. For example, 1 has a certain value while <code>go( )</code> may be executed or not.</p>
<p>Statements are the whole structure, while expressions are the building blocks. For example, a line or a block of code is a statement.</p>
<h2 id="heading-why-you-should-know-the-difference">Why You Should Know the Difference</h2>
<p>First of all, understanding the difference between statements and expressions should make learning new programming languages less surprising. If you're used to JavaScript, you may be surprised by Python's ability to assign an if statement as a variable which is not possible in JavaScript.</p>
<p>Second, it makes it easy to use programming paradigms across different programming languages. </p>
<p>For example, a JavaScript "if statement" cannot be used as an expression because it can't execute to a value – it can only create side effects. Yet, you can use the ternary operator if you want to avoid the side effects of using an if statement in JavaScript. </p>
<p>For this reason, you can understand why some programmers avoid if statements by using the ternary operator in JavaScript. It is because they want to avoid <a target="_blank" href="https://en.wikipedia.org/wiki/Side_effect_(computer_science)">side effects</a>. </p>
<p>It also makes your realize why you have to be always careful about the scope of your variables whenever you use a statement. This is true because statements mostly have side effects to be useful, and it is reasonable to understand the scope of your variables and operations. For example,</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> counter = <span class="hljs-number">0</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addFive</span>(<span class="hljs-params"></span>) </span>{
    counter += <span class="hljs-number">5</span>
    <span class="hljs-built_in">console</span>.log(counter)
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addTwo</span>(<span class="hljs-params"></span>) </span>{
    counter += <span class="hljs-number">2</span>
    <span class="hljs-built_in">console</span>.log(counter)
}

addFive(counter);<span class="hljs-comment">// what will this show in the console?</span>
addTwo(counter);<span class="hljs-comment">// what will this show in the console?</span>
</code></pre>
<p>Hey wait! What would be logged in the console if you ran the code above? </p>
<p>Tell yourself the answer first and then paste the code in the console to confirm. If you you're wrong, you need to learn more about scope and side effects. But if you're right, try to make those functions a bit better to avoid the confusion they may generate.</p>
<p>Knowing the difference also helps you to easily identify non-composable and composable syntaxes (functions, classes, modules, and so on) of a programming language. This makes porting your experience from one programming language to another more interesting and direct.</p>
<h2 id="heading-wrapping-up"><strong>Wrapping Up</strong></h2>
<p>Now that you understand the difference between expressions and statements in programming, and you know why understanding the differences is important, you can identify pieces of code as expressions or statements while coding. </p>
<p>Next time, we'll go even further and help make learning a second programming language easier.</p>
<p>Go and get things done now! See you soon.</p>
<p>I am planning to share a lot about programming tips and tutorials in 2023. If you're struggling to build projects or you want to stay connected with my write-ups and videos, please join my list at <a target="_blank" href="https://youtoocancode.aweb.page">YouTooCanCode</a> or subscribe to my YouTube channel at <a target="_blank" href="https://www.youtube.com/c/youtoocancode">You Too Can Code on YouTube</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Indentation in Python with Examples ]]>
                </title>
                <description>
                    <![CDATA[ It is generally good practice for you not to mix tabs and spaces when coding in Python. Doing this can possibly cause a TabError, and your program will crash. Be consistent when you code - choose either to indent using tabs or spaces and follow your ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/indentation-in-python/</link>
                <guid isPermaLink="false">66c357fcdae03919d93dc076</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ syntax ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 14 Jan 2020 21:46:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9ddf740569d1a4ca3a21.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>It is generally good practice for you not to mix tabs and spaces when coding in Python. Doing this can possibly cause a <code>TabError</code>, and your program will crash. Be consistent when you code - choose either to indent using tabs or spaces and follow your chosen convention throughout your program.</p>
<h3 id="heading-code-blocks-and-indentation">Code Blocks and Indentation</h3>
<p>One of the most distinctive features of Python is its use of indentation to mark blocks of code. Consider the if-statement from our simple password-checking program:</p>
<pre><code class="lang-python"><span class="hljs-keyword">if</span> pwd == <span class="hljs-string">'apple'</span>:
    print(<span class="hljs-string">'Logging on ...'</span>)
<span class="hljs-keyword">else</span>:
    print(<span class="hljs-string">'Incorrect password.'</span>)

print(<span class="hljs-string">'All done!'</span>)
</code></pre>
<p>The lines print(‘Logging on …’) and print(‘Incorrect password.’) are two separate code blocks. These ones happen to be only a single line long, but Python lets you write code blocks consisting of any number of statements.</p>
<p>To indicate a block of code in Python, you must indent each line of the block by the same amount. The two blocks of code in our example if-statement are both indented four spaces, which is a typical amount of indentation for Python.</p>
<p>In most other programming languages, indentation is used only to help make the code look pretty. But in Python, it is required for indicating what block of code a statement belongs to. For instance, the final print(‘All done!’) is not indented, and so is not part of the else-block.</p>
<p>Programmers familiar with other languages often bristle at the thought that indentation matters: Many programmers like the freedom to format their code how they please. However, Python indentation rules are quite simple, and most programmers already use indentation to make their code readable. Python simply takes this idea one step further and gives meaning to the indentation.</p>
<h3 id="heading-ifelif-statements">If/elif-statements</h3>
<p>An if/elif-statement is a generalized if-statement with more than one condition. It is used for making complex decisions. For example, suppose an airline has the following “child” ticket rates: Kids 2 years old or younger fly for free, kids older than 2 but younger than 13 pay a discounted child fare, and anyone 13 years or older pays a regular adult fare. The following program determines how much a passenger should pay:</p>
<pre><code class="lang-python"><span class="hljs-comment"># airfare.py</span>
age = int(input(<span class="hljs-string">'How old are you? '</span>))
<span class="hljs-keyword">if</span> age &lt;= <span class="hljs-number">2</span>:
    print(<span class="hljs-string">' free'</span>)
<span class="hljs-keyword">elif</span> <span class="hljs-number">2</span> &lt; age &lt; <span class="hljs-number">13</span>:
    print(<span class="hljs-string">' child fare)
else:
    print('</span>adult fare<span class="hljs-string">')</span>
</code></pre>
<p>After Python gets age from the user, it enters the if/elif-statement and checks each condition one after the other in the order they are given. So first it checks if age is less than 2, and if so, it indicates that the flying is free and jumps out of the elif-condition. If age is not less than 2, then it checks the next elif-condition to see if age is between 2 and 13. If so, it prints the appropriate message and jumps out of the if/elif-statement. If neither the if-condition nor the elif-condition is True, then it executes the code in the else-block.</p>
<h3 id="heading-conditional-expressions">Conditional expressions</h3>
<p>Python has one more logical operator that some programmers like (and some don’t!). It’s essentially a shorthand notation for if-statements that can be used directly within expressions. Consider this code:</p>
<pre><code class="lang-python">food = input(<span class="hljs-string">"What's your favorite food? "</span>)
reply = <span class="hljs-string">'yuck'</span> <span class="hljs-keyword">if</span> food == <span class="hljs-string">'lamb'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'yum'</span>
</code></pre>
<p>The expression on the right-hand side of = in the second line is called a conditional expression, and it evaluates to either ‘yuck’ or ‘yum’. It’s equivalent to the following:</p>
<pre><code class="lang-python">food = input(<span class="hljs-string">"What's your favorite food? "</span>)
<span class="hljs-keyword">if</span> food == <span class="hljs-string">'lamb'</span>:
   reply = <span class="hljs-string">'yuck'</span>
<span class="hljs-keyword">else</span>:
   reply = <span class="hljs-string">'yum'</span>
</code></pre>
<p>Conditional expressions are usually shorter than the corresponding if/else-statements, although not quite as flexible or easy to read. In general, you should use them when they make your code simpler.</p>
<p><a target="_blank" href="https://docs.python.org/3/reference/lexical_analysis.html#indentation">Python Documentation - Indentation</a></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
