<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Denismacharia</title>
    <description>The latest articles on DEV Community by Denismacharia (@denismacharia).</description>
    <link>https://dev.to/denismacharia</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F996689%2F704f2b7c-7ea1-4299-8193-724bbf601df2.jpg</url>
      <title>DEV Community: Denismacharia</title>
      <link>https://dev.to/denismacharia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/denismacharia"/>
    <language>en</language>
    <item>
      <title>Recursion in Programming</title>
      <dc:creator>Denismacharia</dc:creator>
      <pubDate>Tue, 14 Feb 2023 03:13:38 +0000</pubDate>
      <link>https://dev.to/denismacharia/recursion-in-programming-4j0h</link>
      <guid>https://dev.to/denismacharia/recursion-in-programming-4j0h</guid>
      <description>&lt;p&gt;As a programmer, you must have or will come across tasks that lead to the need for new similar lines of code. The new tasks may appear smaller or may need the repetition of smaller similar commands to handle them. They may require adding other lines of code to terminate them, which leads to increase in the size of the codebase. You can eliminate all this by implementing recursion in your programs. Let's dive into recursion and see what it's all about.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Recursion
&lt;/h2&gt;

&lt;p&gt;Recursion is the process where a function calls itself directly or indirectly. Recursive functions solves problems by calling itself and breaking down original problems into smaller subproblems. When using recursion, you need to define an exit condition to prevent the functions from being called infinitely. The condition that when met terminates the function is known as the &lt;strong&gt;base condition.&lt;/strong&gt;&lt;br&gt;
Recursion is a concept rooted in a number of programming languages as we'll see. &lt;/p&gt;
&lt;h2&gt;
  
  
  Why choose recursion?
&lt;/h2&gt;

&lt;p&gt;One of the main advantages of using recursion is that it reduces the complexity of different tasks and reduces the time spent writing and debugging. It leads to code that is easy on the eye, looks elegant and allows faster completion of tasks. Code that uses recursive functions is significantly less bulky than code that doesn't use it. However, it uses more memory since there is an extensive overhead since the function constantly updates and maintains the stack. &lt;/p&gt;
&lt;h1&gt;
  
  
  Implementing recursion in different programming languages.
&lt;/h1&gt;

&lt;p&gt;Recursion basically works in a similar manner in different languages. However, since each language is unique, there are differences in how recursion is applied. Let's look at how each language implements it using a similar example. &lt;/p&gt;
&lt;h2&gt;
  
  
  Recursion in JavaScript
&lt;/h2&gt;

&lt;p&gt;In JavaScript, the syntax for a recursive function is as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;recurse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// stop calling itself&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;recurse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see it in a practical example. The program is designed to count down numbers to 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;countDown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// displays the number&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// subtracts one from the number&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newNumber&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;countDown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// the base case&lt;/span&gt;

&lt;span class="nx"&gt;CountDown&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// output is&lt;/span&gt;
&lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above JavaScript program, you pass the number as an argument when calling the function. The value of the number reduces by &lt;strong&gt;1.&lt;/strong&gt; The function &lt;code&gt;countdown()&lt;/code&gt; is called until the base function &lt;code&gt;newNumber &amp;gt; 0&lt;/code&gt; reaches &lt;strong&gt;0&lt;/strong&gt; and terminates the function. &lt;/p&gt;

&lt;h2&gt;
  
  
  Recursion in Python
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Python&lt;/code&gt; also uses recursion to write efficient and mathematically elegant code. The syntax for &lt;code&gt;Python&lt;/code&gt; recursive functions is as shown;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
 &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
&lt;span class="c1"&gt;# stop calling itself
&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
&lt;span class="c1"&gt;# recurse
&lt;/span&gt;
&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is a &lt;code&gt;Python&lt;/code&gt; program for the example we are using.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;tri_recursion&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; 
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;tri_recursion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s"&gt;Recursion Example Results"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tri_recursion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Output will be
# 4
# 3
# 2
# 1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function runs itself until the number gets to zero and terminates the program. &lt;/p&gt;

&lt;h2&gt;
  
  
  Recursion in C++
&lt;/h2&gt;

&lt;p&gt;Similar to other programming languages, recursion in &lt;code&gt;C++&lt;/code&gt; works by calling itself over and over again. Its syntax is as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;recurse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="cp"&gt;# base case
&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;}}&lt;/span&gt;
&lt;span class="cp"&gt;# recursive case
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's see it in a practical example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cp"&gt;# The output is
# 5
# 4
# 3
# 2
# 1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Recursion is an essential skill that assists in reducing the bulk of the codebase while increasing the ease of writing and reading code. However, you need to be careful when using recursion since there is a risk of infinite loops and programs that use too much memory and processing power. &lt;/p&gt;

&lt;p&gt;I hope you have learnt something from the article. Find me on twitter &lt;a href="https://twitter.com/devdenis_"&gt;@devdenis_&lt;/a&gt;. Thanks for reading. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>cpp</category>
    </item>
    <item>
      <title>JavaScript Functions</title>
      <dc:creator>Denismacharia</dc:creator>
      <pubDate>Wed, 08 Feb 2023 14:35:09 +0000</pubDate>
      <link>https://dev.to/denismacharia/javascript-functions-3g5e</link>
      <guid>https://dev.to/denismacharia/javascript-functions-3g5e</guid>
      <description>&lt;p&gt;In JavaScript, functions are subprograms in the code that can be called by other code that is either internal or external to the function. A function comprises of a sequence of statements called the function body. Values can be fed to a function as parameters and the feedback given is a value. Functions can be forwarded to other functions, given as feedback by other functions, and can be assigned to variables. Their difference from objects is that they can be called. &lt;/p&gt;

&lt;p&gt;Let's decipher functions.&lt;/p&gt;

&lt;p&gt;Functions occur in different forms. They include;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Function declarations.&lt;/li&gt;
&lt;li&gt;Function expressions.&lt;/li&gt;
&lt;li&gt;Arrow Functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Function Declarations.
&lt;/h2&gt;

&lt;p&gt;Function declarations are function statements that consist of;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;function&lt;/code&gt; keyword.&lt;/li&gt;
&lt;li&gt;The function's name&lt;/li&gt;
&lt;li&gt;The list of parameters to the function in parentheses and separated by commas.&lt;/li&gt;
&lt;li&gt;JavaScript statements that define the function, placed in curly brackets &lt;code&gt;{}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of a simple function named &lt;code&gt;area&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;};}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function is used to calculate the area of a square. It takes only one parameter, which is the length of one side called &lt;code&gt;number&lt;/code&gt; The function is made up of one statements that returns the parameter of the statement which is the &lt;code&gt;number&lt;/code&gt; multiplied by itself. The &lt;code&gt;return&lt;/code&gt; statement shows the value to be returned by the function. &lt;/p&gt;

&lt;p&gt;You can pass parameters to other functions by value. It means that once a new value is assigned to a parameter that was passed to a function, the change is not reflected in the code that called that function. On the other hand, when you pass an object as a parameter, the change can be seen outside the function. When you pass arrays as parameters, a change in values is also visible outside the functions. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that you can quote function declarations before declaring them.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;calcAge&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;yearofBirth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2023&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yearofBirth&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;calcAge&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1980&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// returns 43&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above you should note that the function declaration creates a variable that uses the same name as the function. It shows that function declarations can be referred to by their name in the scope of code that they are defined in, and also in their own body. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is recommended that you use &lt;code&gt;strict mode&lt;/code&gt; when using function declarations. In strict mode, block-level function declarations are scoped to the block and are hoisted to the top of the block hence allowing their use before declaration.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Function Expression
&lt;/h2&gt;

&lt;p&gt;A function expression differs from a function declaration in that the function name can be omitted creating anonymous functions. They can be used as Immediately Invoked Function Expressions which run immediately they are defined. You can use function expressions to define functions inside expressions. On the other hand, you can define function expressions by using the function constructor and a function declaration. Function expressions cannot be referred to before they are created since they do not support hoisting.&lt;/p&gt;

&lt;p&gt;When referring to the current function inside the function body, you must create a named function expression. The name used is local to the function's scope. It doesn't change its name is allocated to a variable. If you choose to omit the function name, it uses the variable (implicit) name. If you name the function, it will use the function (explicit) name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;// "age"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;age0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;// "age"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;newAge&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="nx"&gt;age1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;// "newAge"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;age0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;newAge&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;newAge&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// false (error since newAge == undefined)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The examples above show you how you can name function expressions at different positions and their differences in output. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can create anonymous functions that are unnamed. In the example given below, the function is assigned to &lt;code&gt;const&lt;/code&gt;. The function returns the age after inputting the person's &lt;code&gt;yearofBirth&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calcAge0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;yearofBirth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2023&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yearofBirth&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;calcAge0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1980&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// output; 43&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Arrow Function Expressions
&lt;/h2&gt;

&lt;p&gt;Arrow functions are a more advanced alternative to function expressions. To better understand it, let's start with an example of how you can change a function expression into an arrow function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// an anonymous function expression&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;yearofBirth&lt;/span&gt;&lt;span class="p"&gt;;});&lt;/span&gt;

&lt;span class="c1"&gt;// Replace the Keyword "function" with an arrow placed&lt;/span&gt;
&lt;span class="c1"&gt;// between the argument and the opening body bracket&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2023&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yearofBirth&lt;/span&gt;&lt;span class="p"&gt;;};&lt;/span&gt;

&lt;span class="c1"&gt;// Eliminate the body braces and the keyword "return". &lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2023&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yearofBirth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// eliminate the parameter parentheses&lt;/span&gt;

&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2023&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yearofBirth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example above is an illustration of instances where both parentheses around the parameter and the braces can be omitted. They can only be omitted if the function has only one simple parameter. If there are multiple parameters, no parameters, or default parameters, the parentheses around the parameter list are required. If the function is used to return an expression, braces can be omitted. When the body has additional lines of processing, the &lt;code&gt;return&lt;/code&gt; keyword and the braces are required since arrow functions cannot decide whether you want to return or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Anonymous function&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;unit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;unit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Arrow function&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;unit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;unit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note that arrow functions are always unnamed. If an arrow function needs to call itself, you should use a named function expression or the arrow function can be assigned to a variable so it has a name. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Calling functions
&lt;/h2&gt;

&lt;p&gt;When you define a function, you specify what it does once it is called. Calling a function performs the instructed actions with the given parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;area&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example above calls the area function with the argument that the length of one side is &lt;code&gt;9&lt;/code&gt;. The function is executed and returns the value &lt;code&gt;81&lt;/code&gt;. You must place functions in scope when they are called, but remember that function declarations can be hoisted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;You need to understand how functions work to be a good JavaScript programmer since it is essential in writing efficient code. I hope you have learnt something from the article. If you would like to contact me directly, find me on twitter &lt;a href="https://twitter.com/devdenis_"&gt;@devdenis_.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Fundamentals of JavaScript (Part 1)</title>
      <dc:creator>Denismacharia</dc:creator>
      <pubDate>Sat, 04 Feb 2023 07:23:52 +0000</pubDate>
      <link>https://dev.to/denismacharia/fundamentals-of-javascript-part-1-427d</link>
      <guid>https://dev.to/denismacharia/fundamentals-of-javascript-part-1-427d</guid>
      <description>&lt;p&gt;Whenever you access the internet, most of the sites you access are powered by JavaScript. This article will show you how to write your first JavaScript code and introduce you to JavaScript datatypes.  &lt;/p&gt;

&lt;h1&gt;
  
  
  Getting started with JavaScript
&lt;/h1&gt;

&lt;p&gt;JavaScript is the most popular programming language in the world. It is the programming language that powers the internet. In this article, you will learn the basics of JavaScript language. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Check this out to learn how to &lt;a href="https://www.w3schools.com/tags/att_script_src.asp" rel="noopener noreferrer"&gt;link a JavaScript file to a HTML file.&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Logging 'Hello World" to the console.
&lt;/h2&gt;

&lt;p&gt;To link a JavaScript file to a HTML file, one needs to add the following to the HTML file. &lt;code&gt;&amp;lt;script src="myscripts.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;. The &lt;code&gt;.js&lt;/code&gt; file needs to be in the same folder as the HTML file for the code to work. To ascertain that the JavaScript file is properly linked, you will print hello world as shown;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// The console displays 'Hello World"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  JavaScript Datatypes
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;JavaScript has 8 Datatypes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;Bigint&lt;/li&gt;
&lt;li&gt;Boolean&lt;/li&gt;
&lt;li&gt;Undefined&lt;/li&gt;
&lt;li&gt;Null&lt;/li&gt;
&lt;li&gt;Object &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Strings
&lt;/h3&gt;

&lt;p&gt;Strings are a series of characters written with either single or double quotes. They include special characters, numbers, letters, or a combination of any of them. Strings are immutable and any strings created hold value that cannot be changed. Any operations that appear to change create new strings with the desired modifications. Here are examples of strings;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"John"
"Car"
Let owner1 = "John"
let machine1 = "car"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In all instances the words "car" and "John" are used as strings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Number
&lt;/h3&gt;

&lt;p&gt;In JavaScript, Number data type is used to represent floating-point numbers and integers. JavaScript uses 64-bit floating-point representation for numbers enabling it to represent small and large numbers with high accuracy. However, it limits its ability to represent some numbers accurately leading to approximate values when used in a calculation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a=10;
let b=23;
let c=a+b;
console.log (Z)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variables involved in the above example are numbers and can be used to make arithmetic calculations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bigint
&lt;/h3&gt;

&lt;p&gt;Bigint data type in JavaScript is an numeric primitive that is used to represent integers with arbitrary magnitude. It allows storing integers that are larger than the maximum safe integer limit for Numbers data types. To create a BigInt, you append n to the end of an integer or call &lt;strong&gt;BigInt():&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Let x = 555555555555555
Let y = 555555555555555n
let z = BigInt(555555555555555)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;X is a &lt;strong&gt;number&lt;/strong&gt;, while both y and x are &lt;strong&gt;BigInt&lt;/strong&gt; data types. &lt;/p&gt;

&lt;h3&gt;
  
  
  Boolean
&lt;/h3&gt;

&lt;p&gt;When programming, you will make a lot of decisions that are either true or false. To achieve this, you will need to use Boolean values where you choose from one of two values. They include &lt;em&gt;YES / NO,&lt;/em&gt; &lt;em&gt;ON/OFF,&lt;/em&gt; and &lt;em&gt;TRUE/FALSE.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isTrue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isFalse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Booleans can be used in comparisons and conditions where the value of Boolean expressions is their basis.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;If &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`You are an adult`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`You are not yet an adult`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: You are an adult&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the condition is true, the console displays that the person is an adult, if it's false, it shows that the person is yet to be an adult.&lt;br&gt;
When using Boolean as functions, everything with a value is true while anything without is false. False values include &lt;em&gt;empty strings&lt;/em&gt;, &lt;em&gt;undefined&lt;/em&gt;, &lt;em&gt;null&lt;/em&gt;, &lt;em&gt;false&lt;/em&gt;, and &lt;em&gt;NaN&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;year&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Output : NaN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Year is not a number hence its output will be &lt;code&gt;NaN&lt;/code&gt; which is false in functions.&lt;br&gt;
Booleans can be used as objects but it is not recommended since they can produce unexpected results. Additionally, the &lt;strong&gt;new&lt;/strong&gt; keyword used to define them complicates code and reduces its efficiency. &lt;/p&gt;
&lt;h3&gt;
  
  
  Undefined
&lt;/h3&gt;

&lt;p&gt;It is a primitive data type that is a variable in the global scope. It represents a variable that has not been assigned a value. A statement can also return undefined if the variable being evaluated lacks an assigned value. A function returns undefined if a value was not returned. Although you can use undefined as a variable name it is not recommended since it will maintaining and debugging code difficult.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Null
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;null&lt;/code&gt; value is used to represent intentional absence of any object value. It is treated a falsy for Boolean operations. &lt;code&gt;null&lt;/code&gt; expresses a lack of identification indicating that the variable used lacks identification showing that it does not point to any object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;boy;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value &lt;code&gt;boy&lt;/code&gt; is not identified hence its type is displayed as null.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables and Values
&lt;/h2&gt;

&lt;p&gt;Variables are containers used to store data values. In JavaScript, variables are declared using &lt;strong&gt;Var,&lt;/strong&gt; &lt;strong&gt;Let,&lt;/strong&gt; and &lt;strong&gt;Const.&lt;/strong&gt;&lt;br&gt;
The &lt;strong&gt;Const&lt;/strong&gt; variable is used to declare general rules that are fixed. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;carPrice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;extras&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;Let&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;carprice&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;extras&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above shows that the price of the car and extras is constant. On the other hand, the &lt;strong&gt;let&lt;/strong&gt; variable used to reference the total is not constant.&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;Var&lt;/strong&gt; variable is also used to declare variables that are modifiable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;carType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Audi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;carModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Sports&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;carType&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;carModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Variables are often declared without a value. A value ranges from something that will be provided later or one that requires calculating. Variables declared without a value are given the value &lt;em&gt;Undefined&lt;/em&gt;. In the example given above, the value of the variables used above will change to undefined after the command is executed. &lt;/p&gt;

&lt;p&gt;Thanks for reading, I hope you have learnt something. &lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>crypto</category>
    </item>
    <item>
      <title>Datatypes in JavaScript</title>
      <dc:creator>Denismacharia</dc:creator>
      <pubDate>Mon, 23 Jan 2023 04:28:45 +0000</pubDate>
      <link>https://dev.to/denismacharia/datatypes-in-javascript-5hio</link>
      <guid>https://dev.to/denismacharia/datatypes-in-javascript-5hio</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;What are data types in Javascript?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In Javascript, a data type is a classification of data that determines the type of values a variable can hold. Being a dynamic language, the data type in a variable can change at any point in the execution of instructions. This article will improve your knowledge in javascript data types.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The datatypes include;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Boolean&lt;/li&gt;
&lt;li&gt;Undefined&lt;/li&gt;
&lt;li&gt;Null&lt;/li&gt;
&lt;li&gt;Object&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Number
&lt;/h2&gt;

&lt;p&gt;In JavaScript, the Number data type is used to represent both integers and floating-point numbers. Numbers can be written with or without a decimal point. For example, both 3 and 3.0 are considered to be numbers in JavaScript.&lt;/p&gt;

&lt;p&gt;JavaScript uses a 64-bit floating-point representation for numbers, which means that it can represent large and small numbers with high precision. However, it also means that JavaScript may not be able to represent some numbers exactly. For example, the number 0.1 cannot be represented exactly in 64-bit floating-point format, and may be approximated when used in calculations.&lt;/p&gt;

&lt;p&gt;JavaScript also has several special numeric values that are considered to be of the Number type. These include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;NaN&lt;/code&gt; (not a number): represents the result of a undefined or unrepresentable mathematical operation.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Infinity&lt;/code&gt;: represents positive infinity and negative infinity.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Infinity&lt;/code&gt;: represents negative infinity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JavaScript also has several built-in methods and properties for working with numbers. These include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;Number.isInteger()&lt;/code&gt; method can be used to check if a value is an integer.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Number.isSafeInteger()&lt;/code&gt; method can be used to check if a value is a safe integer (a number that can be exactly represented by the built-in &lt;code&gt;'Number'&lt;/code&gt; type).&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Number.isNaN()&lt;/code&gt; method can be used to check if a value is &lt;code&gt;NaN&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Number.MAX_SAFE_INTEGER&lt;/code&gt; and &lt;code&gt;Number.MIN_SAFE_INTEGER&lt;/code&gt; properties can be used to get the largest and smallest safe integers, respectively.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Number.parseInt()&lt;/code&gt; and &lt;code&gt;Number.parseFloat()&lt;/code&gt; methods can be used to parse a string and return an integer or floating-point number, respectively.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Number.toFixed()&lt;/code&gt; method can be used to convert a number to a string with a specified number of decimal places.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are potential limitations and behavior of numbers in JavaScript when performing mathematical operations, especially with decimals, and when dealing with large numbers where there is a possibility for error due to poor precision, overflow and underflow, and type coercion.&lt;/p&gt;

&lt;h2&gt;
  
  
  String
&lt;/h2&gt;

&lt;p&gt;In JavaScript, the String data type represents a sequence of characters. Strings can be written with single or double quotes, and can contain any combination of letters, numbers, and special characters. For example, the following are all valid strings in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello world&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;123&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Special characters: !@#&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript provides several built-in methods for working with strings. These include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;length&lt;/code&gt; property can be used to get the number of characters in a string.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;charAt()&lt;/code&gt; method can be used to get a specific character from a string by its index.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;indexOf()&lt;/code&gt; method can be used to find the first occurrence of a specified string within another string.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;lastIndexOf()&lt;/code&gt; method can be used to find the last occurrence of a specified string within another string.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;substring()&lt;/code&gt; method can be used to extract a portion of a string.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;slice()&lt;/code&gt; method can be used to extract a portion of a string, similar to substring&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;split()&lt;/code&gt; method can be used to split a string into an array of substrings.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;replace()&lt;/code&gt; method can be used to replace a specified string or regular expression with another string.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;toUpperCase()&lt;/code&gt; and &lt;code&gt;toLowerCase()&lt;/code&gt; methods can be used to convert a string to uppercase or lowercase, respectively.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is important to keep in mind that strings in JavaScript are immutable, which means that once a string is created, its value cannot be changed. Any operations that appear to change a string actually create a new string with the desired modifications.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;JavaScript also has a built-in object called String, which provides additional functionality for working with strings. For example, the &lt;code&gt;String.prototype.concat()&lt;/code&gt; can be used to concatenate two or more strings together.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Boolean
&lt;/h2&gt;

&lt;p&gt;In JavaScript, the Boolean data type is used to represent true or false values. A Boolean value can be either true or false, and is commonly used in conditional statements to check if a certain condition is true or false.&lt;/p&gt;

&lt;p&gt;JavaScript provides several ways to create Boolean values. The simplest way is to use the keywords true and false, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isTrue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isFalse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use logical operators to create Boolean values by combining multiple conditions. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="c1"&gt;// result = true&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="c1"&gt;// result2 = true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use comparison operators to create Boolean values by comparing two values. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isEqual&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="c1"&gt;// isEqual = true&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isNotEqual&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="c1"&gt;// isNotEqual = true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript also provides several built-in methods and properties for working with Boolean values. These include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;Boolean()&lt;/code&gt; function can be used to convert a value to a Boolean.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;!&lt;/code&gt; operator can be used to negate a Boolean value, turning &lt;code&gt;true&lt;/code&gt; into &lt;code&gt;false&lt;/code&gt; and vice versa.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator can be used to perform a logical "and" operation between two Boolean values.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;||&lt;/code&gt; operator can be used to perform a logical "or" operation between two Boolean values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is important to keep in mind that any value can be converted to a Boolean in JavaScript, even if it is not technically a Boolean value. For example, any number that is not &lt;code&gt;0&lt;/code&gt; is considered to be &lt;code&gt;true&lt;/code&gt;, and &lt;code&gt;0&lt;/code&gt; is considered to be &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Boolean values are commonly used in control flow statements such as if-else statements to represent &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Undefined
&lt;/h2&gt;

&lt;p&gt;The undefined data type is used to represent the absence of an object or value. &lt;br&gt;
In JavaScript, a variable can be declared without being assigned a value. In such cases, the variable is of type &lt;code&gt;"undefined"&lt;/code&gt;. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="c1"&gt;// Output: "undefined"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's also possible for a function to not return a value. In such cases, the return value of the function will be &lt;code&gt;"undefined"&lt;/code&gt;. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 
 &lt;span class="c1"&gt;// This function does not return a value&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;example&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: "undefined"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to access the value of an undefined variable, a ReferenceError will be thrown. To avoid this, it's a good practice to check if a variable is undefined before attempting to access its value. You can use the typeof operator to check the data type of a variable, which will return "undefined" if the variable is of type "undefined". For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;car is undefined&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// Output: car is undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's important to note that undefined is a distinct value from null. null is used to represent an intentional non-value, while undefined is used to represent an absence of value or object.&lt;/p&gt;

&lt;p&gt;Variables that have been declared but have not been assigned a value are of type &lt;code&gt;undefined&lt;/code&gt;. To avoid errors, it's a good practice to check if a variable is undefined before accessing its value. &lt;/p&gt;

&lt;h2&gt;
  
  
  Null
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;null&lt;/code&gt; datatype is used to represent intentional lack of a value. It can be assigned to a variable or used as the value of an object property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: "object"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's important to note that, although typeof returns &lt;code&gt;object&lt;/code&gt; for null, null is not an object. It is a special value that represents the absence of an object.&lt;/p&gt;

&lt;p&gt;You can use the null value to explicitly set the value of an object property to an intentional non-value. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;employee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Kendrick&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;occupation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;occupation&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When checking for the absence of a value or object, it is recommended to use null instead of undefined. This is because undefined can have different meanings in different situations, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When a variable has been declared but not assigned a value&lt;/li&gt;
&lt;li&gt;When a function does not return a value&lt;/li&gt;
&lt;li&gt;When an object property does not exist
&lt;code&gt;null&lt;/code&gt; always represents an intentional non-value, making it a more reliable and meaningful value to use when checking for the absence of a value or object.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Object
&lt;/h2&gt;

&lt;p&gt;In JavaScript, the "object" data type is a collection of properties, each of which can hold a value of any data type, including primitive data types and other objects. An object is an instance of the Object class and can be created using the object literal notation or the Object constructor.&lt;/p&gt;

&lt;p&gt;Object Literal Notation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;employee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Kendrick&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;occupation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Developer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Object Constructor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;employee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Kendrick&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;occupation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Developer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In an object, properties are identified by keys, which are strings, and values, which can be of any data type. Properties can be added, modified, or removed using the dot notation or the square bracket notation.&lt;/p&gt;

&lt;p&gt;Dot Notation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1234 mstreet&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: "1234 mstreet"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Square Bracket Notation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;phoneNumber&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;555-555-5555&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;phoneNumber&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: "555-555-5555"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objects can also have methods, which are functions that are properties of an object. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;employee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Kendrick&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;occupation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Developer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, my name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: "Hello, my name is John Doe."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In JavaScript, objects can also be used as associative arrays, where the keys can be used as indices to access the values. This can be useful for storing collections of data where the keys are unique identifiers.&lt;/p&gt;

&lt;p&gt;Javascript is an interesting language that has a lot of capabilities. Developers looking to perfect their javacript skills need to understand Javascript datatypes and make sure they avoid issues that are associated with each datatype for fast, reliable and easily debuggable code. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>career</category>
    </item>
  </channel>
</rss>
