<?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: Saviour Essien</title>
    <description>The latest articles on DEV Community by Saviour Essien (@celebritydev).</description>
    <link>https://dev.to/celebritydev</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%2F262729%2F1d3ffa89-2064-4576-acc6-9169dedb99af.jpg</url>
      <title>DEV Community: Saviour Essien</title>
      <link>https://dev.to/celebritydev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/celebritydev"/>
    <language>en</language>
    <item>
      <title>JavaScript Variables and Data Types</title>
      <dc:creator>Saviour Essien</dc:creator>
      <pubDate>Thu, 05 Mar 2020 23:47:40 +0000</pubDate>
      <link>https://dev.to/celebritydev/javascript-variables-and-data-types-276c</link>
      <guid>https://dev.to/celebritydev/javascript-variables-and-data-types-276c</guid>
      <description>&lt;h1&gt;
  
  
  What are Variables
&lt;/h1&gt;

&lt;p&gt;Variables are like containers or bucket that holds values. To break it into an even simpler relatable form, I will give an illustration. In your kitchen that are different jars or containers holding different items like seasoning cubes, salt, oil etc. These containers are variables which you can easily identify. So if your mom asks for salt you already know which container to bring. That is how variables in Javascript works.&lt;/p&gt;

&lt;p&gt;Javascript is a &lt;em&gt;loosely&lt;/em&gt; typed language which means you don't have to explicitly define the data type a variable should hold, unlike other programming languages.&lt;/p&gt;

&lt;p&gt;In this tutorial, I will be using the ECMAScript 2015 (ES6) syntax as this is part of the newer standard.&lt;/p&gt;

&lt;p&gt;Take a look.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = "Saviour Essien";
let age = 16;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Let me breakdown this code into tiny chunks starting from the left-hand side of the code. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;let&lt;/code&gt; keyword is what tells Javascript we are about to declare a variable &lt;/li&gt;
&lt;li&gt;Then the identifier &lt;code&gt;person&lt;/code&gt; is the name of the variable(container). &lt;/li&gt;
&lt;li&gt;The assignment operator &lt;code&gt;=&lt;/code&gt; like the name implies assigns the variable identifier &lt;code&gt;person&lt;/code&gt; to the value.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;value&lt;/code&gt; Saviour Essien is what is inside the variable(container).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let me spoon feed your more by making my previous illustration more watery.&lt;/p&gt;

&lt;p&gt;Your mother returns from the market with groceries, she calls out your name Ngozi, come and take this groceries to the kitchen. Automatically, you already know where to put each of the items she bought for easy access to you and others.&lt;/p&gt;

&lt;p&gt;So it is safe to say your mother is the &lt;code&gt;programmer&lt;/code&gt; then Ngozi is &lt;code&gt;Javascript&lt;/code&gt;, the groceries are &lt;code&gt;values&lt;/code&gt; then the container which each groceries item goes into is the &lt;code&gt;variable&lt;/code&gt;. Lastly, the name on each container is the &lt;code&gt;identifier&lt;/code&gt;. I don try ✌️ 😂&lt;/p&gt;

&lt;p&gt;Javascript variable identifiers must follow these rules.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name must start with letters (a-z)(A-Z), underscore(_) or dollar sign($).&lt;/li&gt;
&lt;li&gt;Number can be included but it must be after the first letter. e.g &lt;code&gt;item3&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Javascript variables are case sensitive.&lt;code&gt;x&lt;/code&gt; is different from &lt;code&gt;X&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;let x = 25;&lt;br&gt;
let X = 12;&lt;br&gt;
console.log(x);  // 25&lt;br&gt;
console.log(X); // 12&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are two ways of declaring a variable in Javascript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let&lt;/li&gt;
&lt;li&gt;Const also is known as Constant&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the most part, both &lt;code&gt;let&lt;/code&gt; and const are the same the only difference they have is you can reassign a value to &lt;code&gt;let&lt;/code&gt; while you &lt;em&gt;cannot&lt;/em&gt; reassign a value to &lt;code&gt;const&lt;/code&gt; because it will throw an error. &lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Use &lt;code&gt;let&lt;/code&gt; to declare variables which value can change in the future but use &lt;code&gt;const&lt;/code&gt; for values can won't change ever.&lt;/p&gt;

&lt;p&gt;Javascript variables can take in any data type like string, number, object etc.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const location = "Yenagoa"; // String
let phone = 01234567;
const cart = {orange: 6, type: "American Citrius"};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We will look at data types shortly in the next section. Each statement ends with a semicolon &lt;code&gt;;&lt;/code&gt;. This &lt;code&gt;;&lt;/code&gt; semicolon is telling Javascript that is the end of the statement. Although it is not compulsory to end your statement with a &lt;code&gt;;&lt;/code&gt; semicolon. It is advisable for the sake of clean code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Single Line Variable Declaration
&lt;/h3&gt;

&lt;p&gt;Variable can be declared in one line. It is shorter.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let color = 'Red', shade = 'Dark, family = 'Tomatoe';
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The declaration only takes one keyword which can be either &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; each new variable is declared after a comma &lt;code&gt;,&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scoping
&lt;/h3&gt;

&lt;p&gt;In Javascript, there are two types of scopes. The &lt;code&gt;Local&lt;/code&gt; and &lt;code&gt;Global&lt;/code&gt; scope. The &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are both &lt;code&gt;block&lt;/code&gt; scope. This means they can only be accessed within the block statement it was been created in. Although they can also possess the local and global scope. &lt;/p&gt;

&lt;p&gt;Below is a simple example of a block statement.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; for(){
  // This is a block statement
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Going further let take a quick look at how the scoping works.&lt;/p&gt;

&lt;h4&gt;
  
  
  Global Scope
&lt;/h4&gt;

&lt;p&gt;The global scope can be accessed from any function.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const color = 'Yellow';

function addColor() {
    return color;
}

console.log(addColor()); // Yellow
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The above example returns 'Yellow' which was declared outside the function. This is what &lt;code&gt;Global&lt;/code&gt; scoping does.&lt;/p&gt;

&lt;h4&gt;
  
  
  Local Scope
&lt;/h4&gt;

&lt;p&gt;A local scope variable is only accessible within the block or function it was created in.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const color = 'Yellow';

function addColor() {
    //let color = 'Red';
    return color;
}

console.log(addColor()); // Red
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In this example, the variable &lt;code&gt;color&lt;/code&gt; declared inside the function takes precedence against the variable &lt;code&gt;color&lt;/code&gt; declared outside the function. The &lt;code&gt;local&lt;/code&gt; variable will always take &lt;strong&gt;effect&lt;/strong&gt; against a &lt;code&gt;Global&lt;/code&gt; variable.&lt;/p&gt;

&lt;h1&gt;
  
  
  Data Types in Javascript
&lt;/h1&gt;

&lt;p&gt;Our Javascript variable can hold any type of value. Helping the computer determine what type of value is, is why we have data types. Data types help the computer to operate on variables. Without data types, the computer will certainly be confused about what operation it should perform. Because Javascript is dynamically typed, it can automatically determine and assign a data type to a variable value. For example:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let add = 16 + "16";

console.log(add); //1616
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Javascript can automatically identify that the first &lt;code&gt;16&lt;/code&gt; is a number and the second &lt;code&gt;16&lt;/code&gt; is a string. Normally, in Javascript numbers are identified because they don't have an opening and closing quotes &lt;strong&gt;""&lt;/strong&gt; while strings have an opening and closing quotes &lt;strong&gt;""&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There are eight(8) data types available in Javascript.&lt;br&gt;
Number&lt;br&gt;
String&lt;br&gt;
Boolean&lt;br&gt;
Null&lt;br&gt;
Undefined&lt;br&gt;
Objects&lt;br&gt;
Array&lt;/p&gt;

&lt;h2&gt;
  
  
  NUMBER
&lt;/h2&gt;

&lt;p&gt;Numbers are integers. They are the regular numbers we write every day.&lt;/p&gt;

&lt;p&gt;Although numbers can be written with or without decimal like so;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let number1 = 12345;
let number2 = 23.009;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Also notice that numbers are written without quotes.&lt;/p&gt;

&lt;h2&gt;
  
  
  STRING
&lt;/h2&gt;

&lt;p&gt;Strings are letters or text. Strings must be written with opening and closing quotes, the quotes can either be double &lt;code&gt;""&lt;/code&gt; or single &lt;code&gt;''&lt;/code&gt;like so.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let subject = "Javascript";
let level = 'Beginner';
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  BOOLEAN
&lt;/h3&gt;

&lt;p&gt;Boolean only has two values which are &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. It is more like saying &lt;code&gt;yes&lt;/code&gt; or &lt;code&gt;no&lt;/code&gt;. Boolean can be used to determine a condition in Javascript.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let bigNumber = 6 &amp;lt; 2;
console.log(bigNumber); // false
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  NULL
&lt;/h2&gt;

&lt;p&gt;Null means &lt;em&gt;nothing&lt;/em&gt;. The value is doesn't exist.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let amount = null;
console.log(amount); // null
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Undefined
&lt;/h2&gt;

&lt;p&gt;Undefined in Javascript means the value has not been assigned to a variable.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let message;
console.log(message); // undefined.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Noticed I didn't use the &lt;code&gt;=&lt;/code&gt; to assign a value to the &lt;code&gt;message&lt;/code&gt; variable. The &lt;code&gt;undefined&lt;/code&gt; is useful when you wish to use a variable in the future but you are not sure of the value yet to be assigned to it. An example can be user input.&lt;/p&gt;

&lt;h2&gt;
  
  
  OBJECTS
&lt;/h2&gt;

&lt;p&gt;Object can store more than one data collections. Objects process more complexity.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const items = {
  food: "Bole and Fish",
  price: 500,
  portion: 2,
  addSauce: true
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Objects hold &lt;code&gt;key: value&lt;/code&gt; pair. The example above declares a variable called Items. Inside the curly braces &lt;code&gt;{}&lt;/code&gt; are different pairs. Starting from the left-hand side we have the key &lt;code&gt;food&lt;/code&gt; and the value &lt;code&gt;Bole and Fish&lt;/code&gt;. Also, notice that objects can hold different data types like &lt;code&gt;string&lt;/code&gt; &lt;code&gt;number&lt;/code&gt; &lt;code&gt;boolean&lt;/code&gt; as stated in the above example. &lt;/p&gt;

&lt;p&gt;Object is a bit broad. We will engage more on Object in the future.&lt;/p&gt;

&lt;h2&gt;
  
  
  ARRAYS
&lt;/h2&gt;

&lt;p&gt;Arrays fall under objects. An array can hold more than one data value, these values can be string, number, boolean. Arrays are written with an opening and closing square brackets &lt;strong&gt;[]&lt;/strong&gt;.&lt;/p&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const phones = ["Samsung", "Iphone", "Nokia", "Tecno"];

&lt;p&gt;console.log(phones); //(5) ["Samsung", "Iphone", "Nokia", "Tecno"]&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  The Typeof Operator&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Typeof() operator can help us determine the type of Javascript value.&lt;/p&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const movie = "The Hustle";&lt;br&gt;
const  year = 2019;&lt;br&gt;
let interesting = true;&lt;br&gt;
let category = undefined;

&lt;p&gt;console.log(typeof(movie)) // string&lt;br&gt;
console.log(typeof(year)) // number&lt;br&gt;
console.log(typeof(interesting)) // boolean&lt;br&gt;
console.log(typeof(category)) // undefined&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Primitives&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;They are values that can only contain one data. They do not hold extra methods or properties just like Object does. &lt;em&gt;Primitives&lt;/em&gt; are &lt;em&gt;immutable&lt;/em&gt;, this means their value cannot be changed. The following are &lt;em&gt;primitives&lt;/em&gt;.&lt;/p&gt;

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

&lt;p&gt;Thank you for reading through, I believe I have been able to break down some concepts that were confusing to you. Our next topic will be on &lt;em&gt;Javascript Syntax&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recommended Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures"&gt;Mozilla Developer Network - MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://javascript.info/types"&gt;Javascript Info&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeburst.io/javascript-essentials-types-data-structures-3ac039f9877b"&gt;Codeburst&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I still remain your Celebrity Developer 🔥. You can reach out to me on &lt;a href="https://twitter.com/celebritydev"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>variables</category>
      <category>javascript</category>
      <category>newbie</category>
      <category>datatype</category>
    </item>
    <item>
      <title>Introduction to JavaScript for Those With Impostor Syndrome</title>
      <dc:creator>Saviour Essien</dc:creator>
      <pubDate>Mon, 02 Mar 2020 19:19:36 +0000</pubDate>
      <link>https://dev.to/celebritydev/introduction-to-javascript-for-those-with-imposter-syndrome-16em</link>
      <guid>https://dev.to/celebritydev/introduction-to-javascript-for-those-with-imposter-syndrome-16em</guid>
      <description>&lt;p&gt;Before you begin, I want to assure you that JavaScript is a really simple language you will ever learn. With the basics I will be covering in the course of your learning, you will become an expert JavaScript programmer if you stick to these basics.&lt;/p&gt;

&lt;p&gt;JavaSript is a high-level, client-side scripting language that runs on the browser (client). It has been standardized by the ECMAScript language specifications. It turns out is one language you have to learn if you wish to be great at web development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up our Development Environment
&lt;/h2&gt;

&lt;p&gt;For now, we need just two (2) basic tools to start writing JavaScript. Feel free to skip this part if you already have this tools setup on your computer.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Code Editor&lt;/li&gt;
&lt;li&gt;Browser&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the Code Editor, I prefer to use &lt;em&gt;&lt;a href="https://code.visualstudio.com/download"&gt;VS Code&lt;/a&gt;&lt;/em&gt; but they are many out there you can try your hands on depending on your preference.&lt;/p&gt;

&lt;p&gt;Also, I enjoying using &lt;em&gt;&lt;a href="https://www.google.com/chrome"&gt;Chrome&lt;/a&gt;&lt;/em&gt; for testing and debugging my JavaScript application. You can also try &lt;em&gt;&lt;a href="https://www.mozilla.org/en-US/firefox/new"&gt;Firefox&lt;/a&gt;&lt;/em&gt;, &lt;em&gt;&lt;a href="https://www.microsoft.com/en-us/edge"&gt;Microsoft Edge&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;JavaScript is executed on your browser through a JavaScript Engine. On Chrome it is called &lt;strong&gt;V8 Engine&lt;/strong&gt; which is also the engine of the popular Node.js you might have heard about, on Firefox it is known as &lt;strong&gt;SpiderMonkey&lt;/strong&gt;, Microsoft Edge has &lt;strong&gt;Chakra/Chakra Core&lt;/strong&gt; while Apple Safari engine is &lt;strong&gt;JavaSCript Core&lt;/strong&gt;. Just keep this at the back of your mind that JavaScript runs via an engine on the browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  Things JavaScript can Do
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript can change HTML contents&lt;/li&gt;
&lt;li&gt;JavaScript can change HTML attributes&lt;/li&gt;
&lt;li&gt;JavaScript can change CSS styles&lt;/li&gt;
&lt;li&gt;JavaScript can hide/show HTML elements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will see how these various operations are performed in the coming chapters.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Start Using Javascript
&lt;/h3&gt;

&lt;p&gt;JavaScript can be written through different methods. JavaScript can be written as simple as just using an HTML &lt;code&gt;script&lt;/code&gt; tag or through an external Javascript file with a .js extension. First, let's take a look at the written Javascript with the HTML &lt;code&gt;script&lt;/code&gt; tag.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
 console.log("Hello World");
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The Javascript &lt;code&gt;script&lt;/code&gt; tag can be placed inside the &lt;code&gt;head&lt;/code&gt; or the &lt;code&gt;body&lt;/code&gt; HTML element.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
 &amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
   &amp;lt;script&amp;gt;
     console.log("Javascript is Script tag is inside the head");
  &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;

   &amp;lt;h1&amp;gt;Javascript tutorial&amp;lt;/h1&amp;gt;


  &amp;lt;/body&amp;gt;
 &amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;It is recommended to place the &lt;code&gt;script&lt;/code&gt; tag at the bottom part of the body tag.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;!DOCTYPE html&amp;gt;
  &amp;lt;html&amp;gt;
   &amp;lt;body&amp;gt;



  &amp;lt;script&amp;gt;
    console.log("Javascript is Script tag is inside the body");
  &amp;lt;/script&amp;gt;

  &amp;lt;/body&amp;gt;
 &amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The external method of writing Javascript is highly recommended. As you codebase grows you want to make sure you Javascript is not taking up space in your HTML document. It is advisable to separate your Javascript files. Below is an example of an external Javascript file named &lt;em&gt;app.js&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sumUp(a, b) {
  return a + b;
}

sumUp(20, 12);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Outputting Javascript File
&lt;/h3&gt;

&lt;p&gt;Javascript values can be outputted using different in-built functions readily available to you.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;document.write();&lt;/li&gt;
&lt;li&gt;window.alert();&lt;/li&gt;
&lt;li&gt;console.log();&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;document.write() is used to display data. It is majorly for testing purpose.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;!DOCTYPE html&amp;gt;
  &amp;lt;html&amp;gt;
   &amp;lt;body&amp;gt;

   &amp;lt;h1&amp;gt;My first heading&amp;lt;/h1&amp;gt;
   &amp;lt;p&amp;gt;My first paragraph.&amp;lt;/p&amp;gt;

   &amp;lt;script&amp;gt;
     document.write("Learning Javascript");
   &amp;lt;/script&amp;gt;

  &amp;lt;/body&amp;gt;
 &amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;window.alert() is also used to display data. It pops up like an alert box.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
 &amp;lt;html&amp;gt;
 &amp;lt;body&amp;gt;

  &amp;lt;h1&amp;gt;My first heading&amp;lt;/h1&amp;gt;
  &amp;lt;p&amp;gt;My first paragraph.&amp;lt;/p&amp;gt;

&amp;lt;script&amp;gt;
  window.alert("This creates an alert");
&amp;lt;/script&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;console.log() is one of the most popularly used. It is very useful for debugging. To access the console data, you need to open up your developer tools on your browser to access the console.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;!DOCTYPE html&amp;gt;
  &amp;lt;html&amp;gt;
  &amp;lt;body&amp;gt;

  &amp;lt;script&amp;gt;
    console.log("I love using the console");
  &amp;lt;/script&amp;gt;

 &amp;lt;/body&amp;gt;
 &amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Clearly Javascript is simple. I am willing to answer any question you might have. You can follow me on &lt;em&gt;&lt;a href="https://twitter.com/celebritydev"&gt;Twitter&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
See you in the next chapter &lt;strong&gt;Javascript Variables&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>newbie</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The JavaScript String Method - Split();</title>
      <dc:creator>Saviour Essien</dc:creator>
      <pubDate>Fri, 03 Jan 2020 21:11:19 +0000</pubDate>
      <link>https://dev.to/celebritydev/the-javascript-string-method-split-4k85</link>
      <guid>https://dev.to/celebritydev/the-javascript-string-method-split-4k85</guid>
      <description>&lt;p&gt;Hello Fam 😍, I have been on dev.to for two months now. I read the articles most of the time and I love it here. This is my first post here 😎. Happy New Year 💥 💥.&lt;/p&gt;

&lt;p&gt;This post was made as part of my "Did You Know?" series on &lt;a href="https://twitter.com/celebritydev"&gt;Twitter&lt;/a&gt;. I wanted to explain more about the string split method concept. In this post, I will explain what split(); does and a use case of how to apply it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Explanation
&lt;/h1&gt;

&lt;p&gt;The split is a JavaScript &lt;strong&gt;String&lt;/strong&gt; method for modifying and manipulating strings. When using the split() method it returns an &lt;strong&gt;array of substrings&lt;/strong&gt; of the string value. Take a look at the code snippets below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;hobbies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Travelling, Reading, Coding, Cuddling&lt;/span&gt;&lt;span class="dl"&gt;"&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;hobby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;,&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;hobby&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;Result&lt;/span&gt; &lt;span class="c1"&gt;// ["Travelling", " Reading", " Coding", " Cuddling"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let me explain the snippet, the split() method can take in a &lt;strong&gt;separator&lt;/strong&gt; which in this case is a comma (",") it separated the string after each comma sign (,). The split method can also take a &lt;strong&gt;limit&lt;/strong&gt; (optional) and one other form of the separator of which we will discuss shortly. Notice that the resulting array has a spacing before each word? We would get rid of that extra spacing by doing this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;hobbies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Travelling, Reading, Coding, Cuddling&lt;/span&gt;&lt;span class="dl"&gt;"&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;hobby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;, &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;hobby&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;Result&lt;/span&gt; &lt;span class="c1"&gt;// ["Travelling", "Reading", "Coding", "Cuddling"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I have added an extra space after the comma (, ) separator to fix the unwanted space.&lt;/p&gt;

&lt;p&gt;You can also use the &lt;strong&gt;limit&lt;/strong&gt; to end where you want the split should end the array length.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;hobbies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Travelling, Reading, Coding, Cuddling&lt;/span&gt;&lt;span class="dl"&gt;"&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;hobby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&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;hobby&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;Result&lt;/span&gt; &lt;span class="c1"&gt;// ["Travelling", "Reading"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The separator can also separate the string using space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;hobbies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Travelling Reading Coding Cuddling&lt;/span&gt;&lt;span class="dl"&gt;"&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;hobby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &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;hobby&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;Result&lt;/span&gt; &lt;span class="c1"&gt;// ["Travelling", "Reading", "Coding", "Cuddling"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Notice I have gotten rid of the comma(,) in the &lt;strong&gt;hobbies variable&lt;/strong&gt;, then I am separating using space as a separator. This will create a new array value after each space.&lt;/p&gt;

&lt;p&gt;Without the space in between the split(""), the string will split between each character like so&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;move&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Legwork&lt;/span&gt;&lt;span class="dl"&gt;"&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;dance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&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;dance&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;Result&lt;/span&gt; &lt;span class="c1"&gt;// ["L","e","g","w","o","r","k"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;An empty split() will have no effect on the original string instead it will return a single array value&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;move&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Legwork&lt;/span&gt;&lt;span class="dl"&gt;"&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;dance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&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;dance&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;Result&lt;/span&gt; &lt;span class="c1"&gt;// ["Legwork"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Use Case
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qyort_w0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/theboringdude/image/upload/v1578083786/splitjs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qyort_w0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/theboringdude/image/upload/v1578083786/splitjs.jpg" alt="split method use case" title="String split method use case"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for taking the time to read through my post. I hope you find it useful 💖. I'd appreciate contributions or questions.&lt;/p&gt;

&lt;p&gt;I am currently running this series "Did You Know?" for the 366 Days of 2020 on &lt;a href="https://twitter.com/celebritydev"&gt;Twitter&lt;/a&gt;, do well to follow me &lt;a href="https://twitter.com/celebritydev"&gt;@celebritydev&lt;/a&gt; so we can learn together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Side Note
&lt;/h3&gt;

&lt;p&gt;I was listening to Davido's &lt;a href="https://www.naijaloaded.com.ng/download-music/davido-ft-wurld-naira-marley-zlatan-sweet-in-the-middle"&gt;&lt;strong&gt;Sweet in The Middle&lt;/strong&gt;&lt;/a&gt; while writing this post. Go forth and split some strings in the middle 😇&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>didyouknow</category>
      <category>tutorial</category>
      <category>celebritydev</category>
    </item>
  </channel>
</rss>
