Insert an element in specific index in JavaScript Array.

Learn how to insert an element in specific index in array. Image from unsplash (Zdennek) We have some in-built methods to add at elements at the beginning and end of the array. push(value) → Add an element to the end of the array. unshift(value) → Add an element to the beginning of an array. To add …

Essential DOM Operations with JavaScript

Learn about some basic but essential DOM methods in JavaScript Image by Pankaj Patel from Unsplash The below code is what we’ll use to access and manipulate with our JavaScript DOM methods: <div id=”parent”> <div class=”child one”> < /div> <div class=”child children second”> < /div> <div class=”child third”> < /div></div> Select and element by id. It …

Five Ways to Reverse an Array in Javascript

We can reverse an array by both modifying the source array or without modifying the source array. We will look at different ways to do each. Reversing an array by modifying the source array We can use the reverse method available to JavaScript arrays. var numbers = [ ‘1️⃣’ , ‘2️⃣’, ‘3️⃣’, ‘4️⃣’, ‘5️⃣’ ];numbers.reverse();console.log(numbers); // …

Ternary operator in Javascript

Learn about how and when to use ternary operator in Javascript Ternary operator in Javascript Ternary operator is also denoted as conditional operator. Ternary operator is the compact version of if statement. If you’re going to check for simple condition, then ternary operator is highly recommended instead of if block. Example of using normal if …

Default Parameters in Javascript

Learn about how and when to use default parameters in Javascript. default param Default parameter in Javascript The default parameter is a way to set default values for function parameters a value is no passed in (ie. it is undefined). In a function, Ii a parameter is not provided, then its value becomes undefined. In …

Converting a string to camelCase in Javascript

Learn how to convert a string into camelCase in Javascript. image from wikipedia camelCase: Camel case (stylized as camelCase; also known as camel caps or more formally as medial capitals) is the practice of writing phrases such that each word or abbreviation in the middle of the phrase begins with a capital letter, with no …

First class Function in Javascript.

Learn about what is first class function and how to use it , in Javascript. A programming language is said to support First class function , if A function can be assigned to a variable, 2. A function can be passed as an argument, 3. A function can be returned from other function. A function can be …

Check if your variable is an Array in Javascript.

Learn Different ways to check if a variable is array in Javascript. Using Array.isArray() Using toString() method in Object, this method convert the argument to specific type name, If we pass Object.prototype.toString.call(1) returns “[object Number]” , so if we pass array then it results in “[object Array]” . Using instanceof keyword arr instanceof Array; Using toString method …

Exponentiation ** operator in Javascript

The ** operator returns the result of the first variable to the power of the second variable. That is, Math.pow(a,b). Photo by Crissy Jarvis on Unsplash var a = 2;var b = 5; a ** b; // 32 Math.pow(a, b); // 32 If we do like a ** b ** c , then the operation is computed …

Design a site like this with WordPress.com
Get started