<?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: Codecupdev</title>
    <description>The latest articles on DEV Community by Codecupdev (@codecupdev).</description>
    <link>https://dev.to/codecupdev</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%2F849884%2Feaf37011-bc86-4fd0-b921-260230e207b4.png</url>
      <title>DEV Community: Codecupdev</title>
      <link>https://dev.to/codecupdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codecupdev"/>
    <language>en</language>
    <item>
      <title>Learn how to use instanceof in JavaScript</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Tue, 18 Oct 2022 19:53:27 +0000</pubDate>
      <link>https://dev.to/codecupdev/learn-how-to-use-instanceof-in-javascript-3b0i</link>
      <guid>https://dev.to/codecupdev/learn-how-to-use-instanceof-in-javascript-3b0i</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/dpGtGUBSR8I?start=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
In JavaScript instanceof is an operator. An operator is either used for calculations or for logic. The instanceof operator will see if an operand (what we perform the operation on) is an instance of the value we pass. When we use instance of we place the operand on the left and the value we pass on the right. This is shown in the example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;someoperand instanceof somevalue

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;&lt;br&gt;
When we use the instanceof operator it will check whether the operand is an instance of the value we pass and it will also check the prototype chain of the value. The return value will always be a Boolean (true or false). Let’s start by looking at some basic examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const pets = {
  amount: 4
};
pets instanceof String
//Returns ---&amp;gt; false
pets instanceof Number
//Returns ---&amp;gt; false
pets instanceof Object
//Returns ---&amp;gt; true

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

&lt;/div&gt;



&lt;p&gt;In the above example we create an object literal stored in a variable called pets. Inside of the pets object we create a property called amount with a value of four. Next we use the instanceof operator to check whether pets is an instance of String, Number and Object. Both String and Number return false. Even though the value stored inside of pets is a number we are checking the the object itself not the properties inside of the object. As pets is an object when we then go ahead and check whether pets is an instance of Object we get true.&lt;/p&gt;

&lt;p&gt;Let’s look at another example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greeting = "Hello"
greeting instanceof String
//Returns false

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

&lt;/div&gt;



&lt;p&gt;In the above example we declare a variable called greeting and assign to this the string Hello. Next we check whether greeting is an instance of String. We get false. This may surprise you. When we use the instanceof operator we are checking whether it is an instance of the String object we are not checking the type. When we create the greeting variable we use a string literal so it is not actually an instance of String. If we wanted this to return true we would need to do the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greeting = new String("Hello")
greeting instanceof String
//Returns ---&amp;gt; true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The instanceof operator can be useful when you are working with classes and you want to check whether something is an object of a class. Let’s look at an example of this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {}
const honda = new Car()
honda instanceof Car
//Returns ---&amp;gt; true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will wrap up this article with one last example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [1, 2, 3]
arr instanceof Array
//Returns ---&amp;gt; true
arr instanceof Object
//Returns ---&amp;gt; true

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

&lt;/div&gt;



&lt;p&gt;In the above example i declare a variable called arr and I assign to this an array containing some values. Next using the instanceof operator I check whether arr is an instanceof Array. It is so I get true returned. Next i check whether it is an instance of Object. I also get true returned. You can expect functions to work in a similar way. The reason for this is that they inherit from Object in the prototype chain.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this article. Please feel free to post any comments, questions, or feedback, and follow me for more content!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Callbacks in JavaScript</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Thu, 13 Oct 2022 07:04:45 +0000</pubDate>
      <link>https://dev.to/codecupdev/callbacks-in-javascript-3lon</link>
      <guid>https://dev.to/codecupdev/callbacks-in-javascript-3lon</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Ik4cGVcHp-c"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;strong&gt;What is a callback?&lt;/strong&gt;&lt;br&gt;
When we pass a function as an argument to another function and that function is invoked within the outer or parent function we are creating a callback. If you have used in-built methods in JavaScript then it is likely that you have already used a callback. Let’s look at a basic example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(cbFunc) {
  cbFunc();
  cbFunc();
}
function sayHello() {
  console.log("Hello");
}
greet(sayHello);
//Returns ---&amp;gt;
'Hello'
'Hello'

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

&lt;/div&gt;



&lt;p&gt;In the above example, we create a function declaration called greet which accepts a parameter cbFunc. Inside the function body, the cbFunc gets invoked twice. We then create another function declaration called sayHello and inside the body of this function we console.log Hello. This will be our callback function. We then call the greet function and pass in sayHello as the argument so it becomes the callback function.&lt;/p&gt;

&lt;p&gt;When we use callback functions we often use an anonymous function as opposed to an existing function. The reason for this is that if the callback function is not going to be used elsewhere then there is no need to store a named function within the code for the callback. In the following example, we update the code to use an anonymous function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(cbFunc) {
  cbFunc()
  cbFunc()
}
greet(function() {
  console.log("Hello");
})
//Returns ---&amp;gt;
'Hello'
'Hello'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We declare a function declaration called greet which accepts a parameter called cbFunc. This will be the callback function and it gets invoked twice inside the function body. We then call the greet function and pass in the anonymous function directly as the argument. We get the same output when the function runs.&lt;/p&gt;

&lt;p&gt;If you have used setTimeout in JavaScript then you have already been using a callback. The setTimeout function accepts a callback and executes this after a certain period of time has passed. Let’s take a look at an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setTimeout(() =&amp;gt; {
  console.log("Hello");
}, 1000);
//Returns ---&amp;gt; 'Hello'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we pass in an anonymous function as a callback to setTimeout. The callback returns a console log that prints the string Hello. After one second this is printed on the screen.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this article. Please feel free to post any comments, questions, or feedback, and follow me for more content!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>What is bind() in JavaScript?</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Tue, 11 Oct 2022 19:34:07 +0000</pubDate>
      <link>https://dev.to/codecupdev/what-is-bind-in-javascript-3lm9</link>
      <guid>https://dev.to/codecupdev/what-is-bind-in-javascript-3lm9</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/xgbdq7bfpk4"&gt;
&lt;/iframe&gt;
&lt;br&gt;
I recently published an article on using Call() and Apply() in &lt;a href="https://dev.to/codecupdev/call-apply-in-javascript-1dme"&gt;JavaScript&lt;/a&gt;. Bind is often discussed with these methods but it works slightly differently.&lt;/p&gt;

&lt;p&gt;When we use the bind method we are creating a new function but the value of this is set to whatever is passed in when we call the method. Let’s start by looking at a basic example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const studentOne = {
  name: "Abby",
  score: 80
};
function studentScore() {
  return `${this.name} scored ${this.score}.`
};
const result = studentScore.bind(studentOne);
console.log(result());
//Returns ---&amp;gt; Abby scored 80.

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

&lt;/div&gt;



&lt;p&gt;In the above example we create a studentOne object. Inside of this object we set properties for the students name and score. Next we use a function declaration and create a function called studentScore. This function returns a template literal with the students name and score. We go on to declaring a variable called result and assign to this the result of calling the studentScore function but using the bind method. We pass in the studentOne object as the parameter to bind. Lastly inside of a console log we return the result of invoking result.&lt;/p&gt;

&lt;p&gt;When bind is called in the above example a new function is created and stored inside of the variable result. This is stored with the context for this. It is only when we invoke this later inside of the console log that this function actually runs. So to clarify, unlike with call() and apply() the bind method does not execute immediately. It simply returns a new function with the value of this set to what we pass in to the parameters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Passing parameters to bind&lt;/strong&gt;&lt;br&gt;
We can expand upon our prior example by looking at how we can pass additional parameters to bind. If our studentScore function had a parameter, when we call bind we can pass the argument for this in at the same time. Let’s look at an example of this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const studentOne = {
  name: "Abby",
  score: 80
};
function studentScore(subject) {
  return `${this.name} scored ${this.score} in ${subject}.`
};
const result = studentScore.bind(studentOne, "Art");
console.log(result());
//Returns ---&amp;gt; Abby scored 80 in Art.

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

&lt;/div&gt;



&lt;p&gt;We expand upon our prior example by setting subject as a parameter to the studentScore function. Now when we call bind we pass the string Art as an argument. We could equally achieve the same result by passing the Art argument when we called result as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const studentOne = {
  name: "Abby",
  score: 80
};
function studentScore(subject) {
  return `${this.name} scored ${this.score} in ${subject}.`
};
const result = studentScore.bind(studentOne);
console.log(result("Art"));
//Returns ---&amp;gt; Abby scored 80 in Art.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One caveat to note here is that additional arguments will be ignored.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const studentOne = {
  name: "Abby",
  score: 80
};
function studentScore(subject) {
  return `${this.name} scored ${this.score} in ${subject}.`
};
const result = studentScore.bind(studentOne, "Art");
console.log(result("Maths"));
//Returns ---&amp;gt; Abby scored 80 in Art.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we pass in Art as the argument when we call bind. When we call result we then pass in Maths as an argument. This does not replace Art, instead it just adds an additional argument and as the studentScore function only takes one parameter this then gets ignored. If it took two parameters however it would work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const studentOne = {
  name: "Abby",
  score: 80
};
function studentScore(subjectOne, subjectTwo) {
  return `${this.name} scored ${this.score} in ${subjectOne} &amp;amp; ${subjectTwo}.`
};
const result = studentScore.bind(studentOne, "Art");
console.log(result("Maths"));
//Returns ---&amp;gt; Abby scored 80 in Art &amp;amp; Maths.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you enjoyed this article. Please feel free to post any comments, questions, or feedback, and follow me for more content!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Call() &amp; Apply() in JavaScript</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Sun, 09 Oct 2022 18:56:08 +0000</pubDate>
      <link>https://dev.to/codecupdev/call-apply-in-javascript-1dme</link>
      <guid>https://dev.to/codecupdev/call-apply-in-javascript-1dme</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/IOXP-DgTnfM"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
When we use call and apply we are usually working with objects. By using these methods we can inherit object methods from one object to another. So for example if a method was defined on object one it can be called by object two.&lt;/p&gt;

&lt;p&gt;Whilst the concepts behind call and apply are similar the important difference to note is that when you use call you pass the parameters explicitly whereas with apply you pass the second argument as an array. Let’s look at an example to clarify this. We will start by looking at the call method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Call&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;const person = {
  details: function() {
    return `My name is ${this.name}`
  }
}
const bob = {
  name: "Bob"
}
console.log(person.details.call(bob));
//Returns ---&amp;gt; My name is Bob
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we create a person object. Inside of the object we then create a method called details. This method returns a template literal with the persons name. Next, we create another object called bob, bob has a name property and value set. Lastly in a console log we return the result of calling the details method with the call() method and pass in bob as the parameter. If we did not use the call method here we would get the following result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(person.details)
'My name is undefined'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So by using call we can use the details method defined on the person object but on our separate bob object. The this refers to what you pass in as a parameter to call. If we console log the value of this inside of the details method we can be sure of this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const person = {
  details: function() {
    console.log(this)
    //returns ---&amp;gt; {name: 'Bob'}
    return `My name is ${this.name}`
  }
}
const bob = {
  name: "Bob"
}
console.log(person.details.call(bob));
//Returns ---&amp;gt; My name is Bob
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Apply&lt;/strong&gt;&lt;br&gt;
Apply is very similar to call except that we must pass an array as the second parameter. Let’s start by adding a parameter to our initial example which used call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const person = {
  details: function(age) {
    return `My name is ${this.name} and I am ${age} years old.`
  }
}
const bob = {
  name: "Bob"
}
console.log(person.details.call(bob, 12));
//Returns ---&amp;gt; My name is Bob and I am 12 years old.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we now set a parameter for age in the details method which is used in the template literal. When we use the call method we pass in the value for this argument after we pass in the bob object. If we had used apply we would need to use an array here. This is shown in the example below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const person = {
  details: function(age) {
    return `My name is ${this.name} and I am ${age} years old.`
  }
}
const bob = {
  name: "Bob"
}
console.log(person.details.apply(bob, [12]));
//Returns ---&amp;gt; My name is Bob and I am 12 years old.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we had not passed in an array when we used apply we would get the following error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncaught TypeError: CreateListFromArrayLike called on non-object
    at &amp;lt;anonymous&amp;gt;:9:28
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you enjoyed this article. Please feel free to post any comments, questions, or feedback, and follow me for more content!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Tutorial: Nested For Loops in JavaScript</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Sat, 24 Sep 2022 13:35:26 +0000</pubDate>
      <link>https://dev.to/codecupdev/tutorial-nested-for-loops-in-javascript-9na</link>
      <guid>https://dev.to/codecupdev/tutorial-nested-for-loops-in-javascript-9na</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/0CrZ6zVOMh4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I will start by briefly giving an example of a for loop in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [1, 2, 3, 4, 5, 6];
for(let i = 0; i &amp;lt; arr.length; i++) {
  console.log(arr[i]);
}
//Returns ---&amp;gt;
1
2
3
4
5
6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the above example, we start by declaring a variable called arr and assign to this an array that contains the numbers one through to six.&lt;/li&gt;
&lt;li&gt;Next, we create a for loop, We initialise a variable called i which acts as the counter for the loop.&lt;/li&gt;
&lt;li&gt;Next, we use a condition for when the loop should stop running. In our case, we will keep running the loop whilst i is less than the length of the arr array.&lt;/li&gt;
&lt;li&gt;Lastly, for the updater, we say every time the loop runs we should increment i.&lt;/li&gt;
&lt;li&gt;Inside the body of the loop, we use a console log to print out the element of the arr array which is at the index of i when the loop runs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result of this is that every element in the arr array gets printed out.&lt;/p&gt;

&lt;p&gt;Sometimes you may find yourself presented with a more complex data structure such as a nested array. Let’s start by looking at what happens when we use the loop above with this type of data structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [[1, 2], [3, 4], [5, 6]];
for(let i = 0; i &amp;lt; arr.length; i++) {
  console.log(arr[i]);
}
//Returns ---&amp;gt; 
[1, 2]
[3, 4]
[5, 6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we use the same for loop but this time the arr array contains three nested arrays, and each nested array contains two values. When the loop runs we get each of the nested arrays returned. What if we wanted to access the individual elements of the nested arrays? This is where nested for loops become useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nested loops
&lt;/h2&gt;

&lt;p&gt;By using a nested loop we can access the individual elements in the nested arrays. Let’s look at an example of how this would work with the example above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [[1, 2], [3, 4], [5, 6]];
for(let i = 0; i &amp;lt; arr.length; i++) {
  for(let j = 0; j &amp;lt; arr[i].length; j++) {
    console.log(arr[i][j]);
  }
}
//Returns ---&amp;gt;
1
2
3
4
5
6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of our nested loop is that we are able to list out each individual element within the nested arrays. Now let’s break down what is going on here. We already know that the outer loop accesses each of the nested arrays. When this happens the inner loop goes through each element in the nested array. So the console log is essentially saying for the array element of i, which is the array containing 1 and 2 using j iterate through these elements. Let’s break this down a bit further. For the first iteration of the loop we get the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [[1, 2], [3, 4], [5, 6]];
for(let i = 0; i &amp;lt; arr.length; i++) {
  console.log(`I am the outer loop ${arr[i]}`)
  for(let j = 0; j &amp;lt; arr[i].length; j++) {
    console.log(`I am the inner loop ${arr[i][j]}`)
  }
}
//Returns ---&amp;gt;
I am the outer loop 1,2
I am the inner loop 1
I am the inner loop 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the outer loop returns the first nested array which contains the elements 1 and 2. The inner loop then loops through each of the elements of the nested array in turn. Therefore we get 1 and then we get 2.&lt;/p&gt;

&lt;p&gt;This process runs for the entire array of nested arrays. Therefore the final output with these console logs is below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [[1, 2], [3, 4], [5, 6]];
for(let i = 0; i &amp;lt; arr.length; i++) {
  console.log(`I am the outer loop ${arr[i]}`)
  for(let j = 0; j &amp;lt; arr[i].length; j++) {
    console.log(`I am the inner loop ${arr[i][j]}`)
  }
}
//Returns ---&amp;gt;
I am the outer loop 1,2
I am the inner loop 1
I am the inner loop 2
I am the outer loop 3,4
I am the inner loop 3
I am the inner loop 4
I am the outer loop 5,6
I am the inner loop 5
I am the inner loop 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Arrays of Strings
&lt;/h2&gt;

&lt;p&gt;This approach can be equally useful if you have an array of words and you want to loop through each individual letter. Let’s look at an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const names = ["Abby", "Bobby", "Freddy"];
for(let i = 0; i &amp;lt; names.length; i++) {
  console.log(names[i]);
}
//Returns ---&amp;gt;
Abby
Bobby
Freddy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the for loop we iterate through the names array and we can access each element in the names array. This is great but if you want to access the individual elements of the names then a nested loop is a very useful pattern.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const names = ["Abby", "Bobby", "Freddy"];
for(let i = 0; i &amp;lt; names.length; i++) {
  console.log(`I am the outer loop ${names[i]}`)
  for(let j = 0; j &amp;lt; names[i].length; j++) {
    console.log(`I am the inner loop ${names[i][j]}`)
  }
}
//Returns ---&amp;gt;
I am the outer loop Abby
I am the inner loop A
I am the inner loop b
I am the inner loop b
I am the inner loop y
I am the outer loop Bobby
I am the inner loop B
I am the inner loop o
I am the inner loop b
I am the inner loop b
I am the inner loop y
I am the outer loop Freddy
I am the inner loop r
I am the inner loop e
I am the inner loop d
I am the inner loop d
I am the inner loop y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you enjoyed this article. Please feel free to post any comments, questions, or feedback, and follow me for more content!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Primitive Data Types in JavaScript</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Wed, 14 Sep 2022 10:06:42 +0000</pubDate>
      <link>https://dev.to/codecupdev/primitive-data-types-in-javascript-adf</link>
      <guid>https://dev.to/codecupdev/primitive-data-types-in-javascript-adf</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/rlouM9YzFCQ?start=4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a primitive type?
&lt;/h2&gt;

&lt;p&gt;Data can come in all shapes and sizes. We use the term data type to specify the type of a specific value.&lt;/p&gt;

&lt;p&gt;In our everyday language use, we differentiate between letters and numbers and usually, we will use them for different purposes. In programming, it is no different. We call the most basic data types primitives.&lt;/p&gt;

&lt;p&gt;The main features of a primitive data type are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It is not an object (a collection of keys and values)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It does not have its own methods (property of an object which is a function)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is immutable (it cannot be changed and is read-only).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The primitive data types in JavaScript
&lt;/h2&gt;

&lt;p&gt;The primitive data types in JavaScript are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;Boolean&lt;/li&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Null&lt;/li&gt;
&lt;li&gt;Undefined&lt;/li&gt;
&lt;li&gt;Symbol&lt;/li&gt;
&lt;li&gt;BigInt
Let's briefly take a look at each of these types!&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In JavaScript, there is only one type of number and this can be any numerical value with or without decimals. We can use whole numbers, positive numbers and negative numbers. We can also use decimals (also known as floating-point values).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;50
//Whole number
1
//Positive number
-1
//Negative number
0.1
//Decimal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;One of two values true or false (Not wrapped in quotes). A bit like saying yes or no.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



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

&lt;p&gt;The string data type refers to any set of characters wrapped inside single or double-quotes. The following would both be 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;"I am a string";
'I am a string';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Represents nothing or a nonvalue but often this is intentionally set. You could create a variable and intentionally set the value of the variable to null. For example:&lt;br&gt;
&lt;code&gt;let myEmptyVariable = null;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Undefined
&lt;/h2&gt;

&lt;p&gt;Undefined also represents no value. As opposed to null, variables that are defined with no value or variables which have not been declared (created at all) will be given the value of undefined.&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;
console.log(a);
// ---&amp;gt; Returns undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Undefined is often given to us in the form of an error. Functions will return undefined if no return value is set.&lt;/p&gt;

&lt;h2&gt;
  
  
  Symbol
&lt;/h2&gt;

&lt;p&gt;Symbols were introduced in the ES6 version of JavaScript. They are unique identifiers that cannot be mutated and can be created using the function Symbol().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const firstSymbol = Symbol();
const secondSymbol = Symbol();
console.log(firstSymbol === secondSymbol);
// ---&amp;gt; Returns false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  BigInt
&lt;/h2&gt;

&lt;p&gt;Useful for representing large numerical values, Specifically those over 15 digits long. You can create this by placing n at the end of a literal number. It can also be created by using the BigInt constructor and passing the value into the parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ourInteger = 1118998854361892n;
const ourSecondInteger = BigInt(1118998854361892);
console.log(ourSecondInteger);
// ---&amp;gt; Returns 1118998854361892n

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

&lt;/div&gt;



&lt;p&gt;Please feel free to post any comments, questions or feedback!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is String.raw() in JavaScript?</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Tue, 30 Aug 2022 11:22:59 +0000</pubDate>
      <link>https://dev.to/codecupdev/what-is-stringraw-in-javascript-3jb7</link>
      <guid>https://dev.to/codecupdev/what-is-stringraw-in-javascript-3jb7</guid>
      <description>&lt;p&gt;A video of this article is available below:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/lFhMQSfIVms"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this article, I will be introducing raw strings in JavaScript.&lt;/p&gt;

&lt;p&gt;Sometimes when we work with template literals we use them to convert characters. Let’s clarify this with an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(`Monday\nTuesday\nWednesday`);
//Returns ---&amp;gt;
Monday
Tuesday
Wednesday
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we console log a template literal or a template string which contains Monday, Tuesday and Wednesday each separated with the newline character. When this runs each of the words is printed on a new line.&lt;/p&gt;

&lt;h2&gt;
  
  
  String.raw()
&lt;/h2&gt;

&lt;p&gt;JavaScript provides us with the String.raw() tag function which enables us to access the raw string from a template literal. This means we are able to access the string where the escape characters are not processed. Let’s expand on the above example with this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String.raw`Monday\nTuesday\nWednesday`;
//Returns ---&amp;gt; 'Monday\nTuesday\nWednesday'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we use the String.raw() method and pass the template literal as the parameter. We get the same string returned without the newline characters processed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interpolation
&lt;/h2&gt;

&lt;p&gt;When you use the raw method anything interpolated into the string will be processed. Let’s look at an example of this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
console.log(`Sum: ${4+5}`);
//Returns ---&amp;gt; Sum: 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example inside of a console log we use string interpolation to sum 4 and 5. We get the string with the sum returned. Now let’s try doing this with the raw method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String.raw`Sum: ${4+5}`;
//Returns ---&amp;gt; 'Sum: 9'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we use the raw method and pass in the template literal with the interpolated sum. We get the returned string with the completed sum because anything we pass in to be interpolated does get processed by the method.&lt;/p&gt;

&lt;h2&gt;
  
  
  Unicode
&lt;/h2&gt;

&lt;p&gt;Another time that the raw string method is useful is if you are using unicode characters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(`\u2605`);
//Returns ---&amp;gt; ★
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we use the Unicode character to access a star symbol and this is returned to us. Now let's use the raw method on this template literal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String.raw`\u2605`;
//Returns ---&amp;gt; '\\u2605'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We go on to use the raw method passing in the Unicode character. Nothing is processed and we get the raw string returned.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this article. Please feel free to post any comments, questions, or feedback, and follow me for more content!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript String Escape Characters?</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Mon, 11 Jul 2022 06:05:11 +0000</pubDate>
      <link>https://dev.to/codecupdev/javascript-string-escape-characters-khb</link>
      <guid>https://dev.to/codecupdev/javascript-string-escape-characters-khb</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vH7mpnQH51Y"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In JavaScript when we are working with strings sometimes we want to break up the string in some way. We have some escape characters which we can use to help us with this challenge.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;\’ Single quote&lt;/li&gt;
&lt;li&gt;\” Double quote&lt;/li&gt;
&lt;li&gt;\n Newline&lt;/li&gt;
&lt;li&gt;\ Backslash&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Quotes
&lt;/h2&gt;

&lt;p&gt;When you are working with strings if you want to use a quote within the string you cannot use the same quote marks for the quote inside the string as the ones you wrap the string in. Let’s look at some examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const quote = "A famous quote is "I think, therefore I am" "
//Returns ---&amp;gt; Uncaught SyntaxError: Unexpected identifier
const secondQuote = 'A famous quote is 'I think, therefore I am' ';
//Returns ---&amp;gt; Uncaught SyntaxError: Unexpected identifier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we start by declaring a variable with the identifier quote and assign to this a string enclosed in double quote marks which contains a quote which is also enclosed in double quote marks. Next we create a second variable called secondQuote which repeats the same steps again but this time it uses single quote marks. Both of these return a syntax error. One way around this problem would be to use different quote marks for the quote as is shown in the example below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const quote = "A famous quote is 'I think, therefore I am' "
const secondQuote = 'A famous quote is "I think, therefore I am" ';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example the string stored inside the variable quote uses single quote marks for the quote and double quote marks for the string. The string for the secondQuote variable uses single quote marks for the string and double quote marks for the quote. Both of these work. Alternatively we could use the escape characters for these as shown in the example below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const quote = "A famous quote is \"I think, therefore I am\" "
const secondQuote = 'A famous quote is \'I think, therefore I am\' ';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we use a backslash and the double quote mark at the start and end of the string stored inside the quote variable. We repeat the same steps but we use a backslash and a quote mark for the string stored inside the secondQuote variable.&lt;/p&gt;

&lt;p&gt;Another time this is useful is if you wish to use apostrophes within the string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const phrase = 'You\'ve had eight cookies';
//Returns ---&amp;gt; "You've had eight cookies"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Newline
&lt;/h2&gt;

&lt;p&gt;When you want to break up your string over multiple lines, one option available is to use the newline character. We place this where we want the new line to appear. Let’s look at an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Monday, Tuesday, Wednesday";
//Returns ---&amp;gt; 'Monday, Tuesday, Wednesday'
"Monday,\nTuesday,\nWednesday";
//Returns ---&amp;gt; 
"Monday,
Tuesday,
Wednesday"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Backslash
&lt;/h2&gt;

&lt;p&gt;If you want to use a backslash within your string you need to use two back slash characters. Given we use the backslash when we use an escape character we can’t just use a single backslash in a string. Let’s look at some examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Hello \";
//Returns ---&amp;gt; Uncaught SyntaxError: Invalid or unexpected token
"Hello \\";
//Returns ---&amp;gt; 'Hello \'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Introducing Promises in JavaScript</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Sat, 25 Jun 2022 09:07:41 +0000</pubDate>
      <link>https://dev.to/codecupdev/introducing-promises-in-javascript-1dpp</link>
      <guid>https://dev.to/codecupdev/introducing-promises-in-javascript-1dpp</guid>
      <description>&lt;p&gt;If you would like to see a video of this article it is available below.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/xwvZEuc8cHc"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;strong&gt;What is asynchronous?&lt;/strong&gt;&lt;br&gt;
Usually, when you hear about promises in JavaScript, you also hear the word asynchronous. What is asynchronous? First, we have synchronous which means something which is performed step by step. When you are walking you put one foot in front of the other and you don’t do both at the same time unless you are jumping! Another example is waiting for a kettle to boil before you make a cup of tea. Asynchronous on the other hand means you can do other things in the background without everything stopping and waiting. It’s a bit like saying you might watch some tv whilst you wait for the kettle to boil as opposed to standing and staring at the kettle waiting on it.&lt;/p&gt;

&lt;p&gt;JavaScript is what we call a single-threaded language, this means only one thing can happen at once and at one time. Asynchronous JavaScript is the way in which background tasks (such as requests to servers) can happen without everything grinding to a halt due to waiting for a single task to complete. It means that the asynchronous tasks get run outside of the main flow of the program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introducing promises&lt;/strong&gt;&lt;br&gt;
In your day-to-day life, you often promise people something in advance of actually doing it. Perhaps you said, “I promise I will clean the dishes,” or, “I promise I will buy some milk.” This is essentially how promises in JavaScript work. When you use a promise, you are usually writing asynchronous code and you are making a promise or a transaction for something that is going to be done.&lt;/p&gt;

&lt;p&gt;Once the promise is done, then the task is either fulfilled or failed. This is like you either fulfilled your promise of buying milk or you forgot so your promise failed.&lt;/p&gt;

&lt;p&gt;There are two parts to understand when you are working with promises. Creating the promise and then how to use the promise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a promise&lt;/strong&gt;&lt;br&gt;
A promise is a constructor function so you must use the new keyword and a promise becomes Promise when you create one. The promise takes a function as the argument with two parameters: resolve and reject.&lt;/p&gt;

&lt;p&gt;Resolve and reject are functions that can be called so they need to be executed with parentheses. Resolve and reject get used to determine what happens when the promise runs. Let’s look at the basic syntax for creating a promise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ourPromise = new Promise((resolve, reject) =&amp;gt; {
});
console.log(ourPromise);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we use const and declare a variable called ourPromise. Initially, this is uninitialised but then we use the keywords new and Promise (promise is a constructor function). We pass in the resolve and reject parameters. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise states&lt;/strong&gt;&lt;br&gt;
There are three states which promises can have. Pending, fulfilled and rejected. The ourPromise we created does not resolve or reject anything so it will remain indefinitely in the pending state. It’s a bit like someone waiting on you to go out and buy your milk.&lt;/p&gt;

&lt;p&gt;To complete a promise, we use resolve or reject. Resolve means that the promise succeeds and reject means it fails. Any argument can be passed into resolve and reject but often when we work with promises we are making data requests so it is an object that you would extract some data from.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resolving and Rejecting&lt;/strong&gt;&lt;br&gt;
Let’s update our example to show the outcome of resolving and then rejecting the promise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ourPromise = new Promise((resolve, reject) =&amp;gt; {
  resolve();
});
console.log(ourPromise);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ourPromise = new Promise((resolve, reject) =&amp;gt; {
  reject();
});
console.log(ourPromise);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we resolve our promise the state becomes fulfilled. When we reject it the state becomes rejected. Now we will also update our example so it better represents a request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ourPromise = new Promise((resolve, reject) =&amp;gt; {
  let didGetMilk = true;

  if(didGetMilk) {
    resolve("We got the milk");
  } else {
    reject("Ooops we did not get the milk");
  }
});
console.log(ourPromise);
//Returns ---&amp;gt; Promise {&amp;lt;fulfilled&amp;gt;: 'We got the milk'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we create a variable called didGetMilk which can fake a response from a server. We are setting this to true for demonstration purposes. We then use an if/else statement which resolves or rejects the promise with a message based on the value of the didGetMilk variable.&lt;/p&gt;

&lt;p&gt;When we run this because didGetMilk is true the promise gets resolved with the message. If we set didGetMilk to false the promise would be rejected as shown in the example below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ourPromise = new Promise((resolve, reject) =&amp;gt; {
  let didGetMilk = false;

  if(didGetMilk) {
    resolve("We got the milk");
  } else {
    reject("Ooops we did not get the milk");
  }
});
console.log(ourPromise);
//Returns ---&amp;gt; Promise {&amp;lt;rejected&amp;gt;: 'Ooops we did not get the milk'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using promises and understanding then&lt;/strong&gt;&lt;br&gt;
We can use then to run code once the promise has been resolved. Then is a method which will be executed immediately after the promise has been fulfilled.&lt;/p&gt;

&lt;p&gt;We can pass a callback to then which has the code which will be run once the promise is fulfilled. Let’s update our example to show this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ourPromise = new Promise((resolve, reject) =&amp;gt; {
  let didGetMilk = true;

  if(didGetMilk) {
    resolve("We got the milk")
  } else {
    reject("Ooops we did not get the milk");
  }
});
ourPromise.then(res =&amp;gt; {
  console.log(res, "RES");
});
console.log(ourPromise);
//Returns ---&amp;gt; 
Promise {&amp;lt;fulfilled&amp;gt;: 'We got the milk'}
We got the milk RES
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we set didGetMilk back to true so the promise will be resolved. We go on to use the then method on our promise. We set a parameter res for the result and we console log the result of this.&lt;/p&gt;

&lt;p&gt;When the promise runs we get the fulfilled status but we also see the res parameter printed. The res gets passed from the argument we give to the resolve method. Let’s change the argument we give to resolve to solidify our understanding of this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ourPromise = new Promise((resolve, reject) =&amp;gt; {
  let didGetMilk = true;

  if(didGetMilk) {
    resolve({message: "We got the milk"})
  } else {
    reject("Ooops we did not get the milk");
  }
});
ourPromise.then(res =&amp;gt; {
  console.log(res.message, "RES");
});
console.log(ourPromise);
//Returns ---&amp;gt; 
Promise {&amp;lt;fulfilled&amp;gt;: 'We got the milk'}
We got the milk RES
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we change the argument we pass to resolve to be an object. The object has a message key with the string as the value. We update the console log of the then callback to print the message from the object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Catch&lt;/strong&gt;&lt;br&gt;
When the promise gets rejected we handle this by using catch. It works in a similar way to when we use then for resolving the promise. Catch will be executed immediately after the promise is rejected. Let’s look at an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ourPromise = new Promise((resolve, reject) =&amp;gt; {
  let didGetMilk = false;

  if(didGetMilk) {
    resolve({message: "We got the milk"})
  } else {
    reject("Ooops we did not get the milk");
  }
});
ourPromise
.then(res =&amp;gt; {
  console.log(res.message, "RES");
})
.catch(error =&amp;gt; {
  console.log(error);
})
console.log(ourPromise);
//Returns ---&amp;gt; 
Promise {&amp;lt;rejected&amp;gt;: 'Ooops we did not get the milk'}
Ooops we did not get the milk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time when the code runs the promise gets rejected so the code in the catch gets run and we get the argument we passed to the call to reject printed to the console.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this article, please feel free to post any comments, questions, or feedback, and follow me for more content!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What are Template Literals in JavaScript</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Sat, 21 May 2022 07:36:20 +0000</pubDate>
      <link>https://dev.to/codecupdev/what-are-template-literals-in-javascript-3j3e</link>
      <guid>https://dev.to/codecupdev/what-are-template-literals-in-javascript-3j3e</guid>
      <description>&lt;h2&gt;
  
  
  What are Template Literals?
&lt;/h2&gt;

&lt;p&gt;In the ES6 version of JavaScript, template literals were introduced. Before ES6 if we had a variable that we wanted to use within our strings we would have to do something like the following example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printDrink() {
  var drink = "Tea";
  return "My favourite drink is" + " " + drink;
}
console.log(printDrink());
//Returns ---&amp;gt; My favourite drink is Tea
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we create a function declaration called printDrink. Inside the function, we create a variable called drink. We assign to the variable the string “Tea”. The function returns a string which uses concatenation (the addition symbols) to print out a string and the drink variable. When the function is invoked we get the string returned.&lt;/p&gt;

&lt;p&gt;Template literals offer a clean way to interpolate (inject) the variables or expressions into the string as opposed to having to do the concatenation. A template literal is enclosed in back-ticks instead of the usual double or single quote marks. String interpolation describes when variables are injected into a string. The variable you wish to interpolate is wrapped inside curly braces and started with a dollar sign. The variable itself is placed inside the curly braces.&lt;/p&gt;

&lt;p&gt;Let’s look at the prior example but this time using a template literal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printDrink() {
  var drink = "Tea";
  return `My favourite drink is ${drink}`;
}
console.log(printDrink());
//Returns ---&amp;gt; My favourite drink is Tea
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we keep the same function declaration and drink variable. This time we use a template literal. The template literal is enclosed within back ticks and returns the string. Using interpolation the drink variable is injected into the template literal. When the function is invoked we get the same return value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi line strings
&lt;/h2&gt;

&lt;p&gt;Another useful feature of template literals is that we can span our string over multiple lines. Prior to ES6 you would have to either use string concatenation or a new line character (\n) to achieve this. I briefly show an example of this below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var ourString = "First line\nSecond line\nThird line\n";
console.log(ourString);
//Returns ---&amp;gt; 
First line
Second line
Third line
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With template literals we no longer have to worry about this. If we want to create a multi line string we can do so by enclosing the string in back ticks and separating the lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let ourString = `First line
Second line 
Third line`;
console.log(ourString);
//Returns ---&amp;gt; 
First line
Second line
Third line
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you enjoyed this article! If you would like to watch a video tutorial it is available here.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/f4KHwBGFwAo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>An Introduction to Logical Operators in JavaScript</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Mon, 09 May 2022 10:56:43 +0000</pubDate>
      <link>https://dev.to/codecupdev/an-introduction-to-logical-operators-in-javascript-4l63</link>
      <guid>https://dev.to/codecupdev/an-introduction-to-logical-operators-in-javascript-4l63</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xYqFHMUz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uq7lpsaq0dm6m1cqxmqk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xYqFHMUz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uq7lpsaq0dm6m1cqxmqk.jpg" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A video of this article can be found below.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/IYc16TvyOoY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;There are three logical operators in JavaScript the AND operator, The OR operator and the NOT operator. Logical operators enable us to make the logic in our code a bit more complex and allow us to check two or more conditions at once.&lt;/p&gt;

&lt;p&gt;If we had an application that allowed customers to order groceries, we may have a scenario where a customer wanted to order some bananas. Before we can allow them to go ahead and place the order we need to check we have bananas in stock. Things get a little more complex if we also want to make sure a customer is not ordering all the bananas we have in stock because this could annoy other customers meaning they could not order any. Now we have a situation where when a customer orders some bananas we must check that we have bananas in stock and that the customer is ordering 5 or less bananas. This is the sort of scenario where a logical operator would be handy…&lt;/p&gt;

&lt;h2&gt;
  
  
  AND
&lt;/h2&gt;

&lt;p&gt;We will start by looking at the AND operator. The AND operator consists of two ampersand symbols and it checks whether two conditions evaluate to true. To be clear when we say a condition this might be whether 2 is greater than one. Going back to the stock example, checking whether the number of bananas in stock greater is than zero is one condition and then whether a customer is ordering less than or equal to 5 bananas is another condition.&lt;/p&gt;

&lt;p&gt;When we use the AND operator the possible outcomes are as follows:&lt;/p&gt;

&lt;p&gt;If both conditions evaluate to be true the return value will be true.&lt;br&gt;
If none of the conditions evaluate to be true the return value will be false.&lt;br&gt;
If only one condition is false the entire group of conditions will evaluate to false.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mVOVyT36--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r56wpsm7dd78p4umkrso.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mVOVyT36--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r56wpsm7dd78p4umkrso.jpg" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above is an example of using the AND operator where the return value is true, this is the case because 5 is less than 100 AND 10 is less than 100.&lt;/p&gt;

&lt;p&gt;So now we will try this again but this time we will set the first expression to a condition that evaluates to true and the second expression to a condition that evaluates to false.&lt;/p&gt;

&lt;p&gt;This time we get false as the return value because whilst 5 is less than 100, 1000 is not less than 100, therefore the whole expression does not evaluate to true.&lt;/p&gt;

&lt;h2&gt;
  
  
  OR
&lt;/h2&gt;

&lt;p&gt;Moving on to the OR operator. The OR operator is made up of two pipe characters (||). Using the or operator we can check whether one of a set of conditions is true.&lt;/p&gt;

&lt;p&gt;If one of the conditions is true then the next condition will not even be checked because the OR operator only checks the remaining conditions if the prior conditions were false. In this case, the return value would be true.&lt;br&gt;
If none of the conditions are true then false is the return value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5W1AnNFQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqa4nn3arh8qsqbz4iqv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5W1AnNFQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqa4nn3arh8qsqbz4iqv.jpg" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, we first check whether 8 is less than 9. This evaluates to true so the second expression does not even need to be checked and we get true as the return value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AJleC-ty--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fbzhdj42bl72rtg7pkdl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AJleC-ty--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fbzhdj42bl72rtg7pkdl.jpg" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we try this again and check whether 100 is less than 9 or whether 100 is less than 11. As the first expression here is false we move on and check the second condition, the second condition is also false therefore the return value is false.&lt;/p&gt;

&lt;h2&gt;
  
  
  NOT
&lt;/h2&gt;

&lt;p&gt;Lastly, we have no operator. The NOT operator (!) reverses or negates the value of a boolean so the NOT operator will return false if the value is true and true if the value is false. The return value of the NOT operator will always be a boolean.&lt;/p&gt;

&lt;p&gt;The NOT operator can be used with non-boolean data types but these values will be converted into booleans based on whether the value is truthy or falsy before being negated and you can find a list of the false values on the mdn site &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Falsy"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2MD1_NpP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ez3c6zbq14h5s1wdv6rb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2MD1_NpP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ez3c6zbq14h5s1wdv6rb.jpg" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, we initialize a variable passwordIsRequired with the boolean value false. In the console.log we negate this value with the NOT operator. This means that we get true as the return value.&lt;/p&gt;

&lt;p&gt;Let's try another example so if we say is 20 less than 30 we will get true. Now if we use the not operator and perform this again we get false because the return value is now negated. The final two examples show what happens if we use the not operator with the boolean values true and false. Again the values get negated so !true returns false and !false returns true.&lt;/p&gt;

&lt;p&gt;Please feel free to post any comments, questions or feedback!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Introducing Comparison Operators in JavaScript</title>
      <dc:creator>Codecupdev</dc:creator>
      <pubDate>Sun, 01 May 2022 14:55:05 +0000</pubDate>
      <link>https://dev.to/codecupdev/introducing-comparison-operators-in-javascript-5a6h</link>
      <guid>https://dev.to/codecupdev/introducing-comparison-operators-in-javascript-5a6h</guid>
      <description>&lt;p&gt;JavaScript provides us with a set of operators called comparison operators. Comparison operators let us compare values and return a boolean (true or false).&lt;/p&gt;

&lt;p&gt;If you would like to watch a video of this post you can view it here:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/0F7z4SapLNQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The first set of these operators we will look at are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Greater than: Checks if a value is greater than something.&lt;/li&gt;
&lt;li&gt;Less than: Checks if a value is less than something.&lt;/li&gt;
&lt;li&gt;Greater than or equal: Checks if a value is greater than or it is equal to something.&lt;/li&gt;
&lt;li&gt;Less than or equal: Checks if the value is less than or it is equal to something.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8qjbpkrudras1sd4mpcc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8qjbpkrudras1sd4mpcc.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we were making a program that was based on supermarket stock we might encounter a situation where we only want the user to be able to place an order if we had bananas in stock. To do this we would want to check that the number of bananas available was greater than 0, this would be an example of using the greater than operator.&lt;br&gt;
Later we may then want to limit the amount of bananas a customer is able to order in one go to 5 to ensure the order system was fair. In this case, we would want to check that the order count of bananas was less than or equal to 5 and we would use the less than or equal to operator.&lt;/p&gt;

&lt;p&gt;We will start with a simple example of using the greater than operator. We will check if one is less than 2 and we get true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 &amp;lt; 2
// ---&amp;gt; Returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we move on and check whether one is greater than two and we get false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 &amp;gt; 2
// ---&amp;gt; Returns false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s do an example with the less than or equal operator. We will check if 5 is less than or it is equal to 5, we get true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5 &amp;lt;= 5
// ---&amp;gt; Returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next set of comparison operators let us check whether a value is equal to another value and return a boolean based on whether or not this is the case. These operators consist of the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1s6oox4h77rj2gl73yp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1s6oox4h77rj2gl73yp.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Equality operator (sometimes called loose equality)&lt;/li&gt;
&lt;li&gt;Inequality operator(sometimes called loose inequality)&lt;/li&gt;
&lt;li&gt;Strict equality&lt;/li&gt;
&lt;li&gt;Strict inequality&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In JavaScript, we have what is called loose equality and also strict equality. When we use the loose equality operator, Javascript performs what is called type coercion.&lt;/p&gt;

&lt;p&gt;Type coercion is the automatic conversion of one data type to another data type. So if we wanted to compare the integer zero to a string containing zero the comparison using loose equality would return true. This is because the string zero will be coerced to the integer type and then the comparison performed would be the number 0 compared with number 0. On the other hand, if we performed the same comparison using the strict equality operator the return value would be false because the strict equality operator does not perform any type coercion.&lt;br&gt;
So let’s start by trying out the equality operator. We will compare the integer five with the string 5. As you can see we get true because the string five is coerced to the integer type before the comparison is performed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5 == '5'
// ---&amp;gt; Returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s try this again but compare the integer 5 to the string 6. These are not equal so we get false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5 == '6'
// ---&amp;gt; Returns false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we did this again and use the inequality operator we get true because the inequality operator checks to see that the values are not equal to one another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6 != '6'
// ---&amp;gt; Returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, we will look at the strict equality operator. We will compare the integer ten to the integer ten. These values are both the same so we get true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 === 10
// ---&amp;gt; Returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s try changing this a bit and compare the integer ten to the string ten. Now we get false and this is because we are using the strict equality operator and therefore this time the string will not be coerced.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 === '10'
// ---&amp;gt; Returns false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, if we check that these values are not equal using the strict inequality operator we will get true because they are not from the same data type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 !== '10'
// ---&amp;gt; Returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please feel free to post any comments, questions, or feedback!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
