My Development Notes

Programming Made Easier


Category: JavaScript

  • Rock-Paper-Scissors Game Logic in JavaScript

    Rock-Paper-Scissors Game Logic in JavaScript

    This is the total breakdown of the Rock-Paper-Scissors Game Logic in JavaScript. Here’s the full code first. Afterwards I’ll break down as to how it all works behind the scenes. Here, the code runs from top to bottom and executes accordingly. Part 1 Let’s now break down the first part of the game. The first…

  • What is a Constructor Function in JavaScript

    What is a Constructor Function in JavaScript

    A constructor function is a type of function which creates a new object in JavaScript. Unlike other functions, the name given to a constructor function starts with capital letter, i.e., we have to use the pascal notation in its naming convention. Also this keyword is used to set the properties in constructor functions. Let’s explain…

  • Smallest Integer in an Array – JavaScript

    Smallest Integer in an Array – JavaScript

    To find the smallest integer in an array, we can use various methods. Firstly, let’s use the Math.min() method: Using reduce() method: Let’s break down Example 2 now using some visuals for you to understand: Other ways to do this:

  • Sum of elements in an array in JavaScript

    Sum of elements in an array in JavaScript

    This is how the sum of elements in an array should look like: We can use the reduce() method to find the sum of elements in an array : Here, the reduce() method actually takes two parameters, the first one we can call accumulator, and the second one, current. So, here in the above example,…

  • Factorial of a given number in JavaScript

    Factorial of a given number in JavaScript

    Factorial of an integer ‘n’ is represented by ‘n!’. Factorial of an integer n is the product of all positive integers less than or equal to n. Examples : Here’s a way to find the factorial of a given number: Here the variable factInt is initialized at 1 since the function will always be greater…

  • Square of every digit of a given number – JavaScript

    Square of every digit of a given number – JavaScript

    Example 1 In order to square every digit of a number in JavaScript, we can use the following function: Explanation and break-down In order to know what is happening within this function we have to break it down. So, in the first step we split the digits of the number to a string of individual…

  • Key-Value Pairs in JavaScript Objects

    Key-Value Pairs in JavaScript Objects

    JavaScript objects have keys (or properties), and values. Let’s take a look at this JS object example with some keys and values, keys are on the left, values on the right : Now let’s add some additional key value pairs to the object. Here’s one way to do that: So, if you add the above…

  • Reversing a string in JavaScript – Explanation

    Reversing a string in JavaScript – Explanation

    Say you want to reverse a string passed in a JavaScript functionality as below: There are various ways to reverse the string passed above. Let’s look at them and break them down for you to understand. So the first and the most popular method used to achieve the reverse string functionality is using the split-reverse-join…

  • The Spread Operator (…) or the three dots in JavaScript

    The Spread Operator (…) or the three dots in JavaScript

    The Spread Operator in JavaScript simply copies all the elements of an array and outputs them to the console. It is represented by … i.e., the three dots. Let’s understand it better using the simple code below: The spread Operator has been around since JavaScript ES6. It helps in extracting properties from old objects or…

  • JavaScript Array splice() vs slice() methods

    JavaScript Array splice() vs slice() methods

    The splice() method is used to add or remove multiple elements in an array. It can add in or remove any number of consecutive elements from anywhere inside the array. It also overwrites the original array. It can take up to three parameters, the third one basically comprising of elements to add to an array.…