Posts for Javascript

Deven
Deven wrote

JavaScript Submit form example

Forms are an integral part of any website. Most websites often contain the Contact Us form. Forms collect the user information & send it to a server to store it in a database. In today’s post, we are going to learn how you can collect the user information via HTML forms & submit it to […]

October 19, 2021 in Code examples
Deven
Deven wrote

How to use Promise.then() in JavaScript

The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise. Promises can be chained one after the other using the .then() chain. The subsequent promises in .then chain are only executed once the current promise resolves successfully. If the current promise rejects […]

October 15, 2021 in Code examples
Deven
Deven wrote

Solved – cannot set property ‘innerhtml’ of null

In this article, you will learn how to solve cannot set property ‘innerhtml’ of null error in JavaScript. Let’s look at a code example that produces the same error. Output In order to solve cannot set property ‘innerhtml’ of null error in JavaScript by moving our <script> below our paragraph like in the code snippet below: output

March 11, 2021 in Errors solved

How to Download File in Javascript

In this article, you will learn how to download a file in Javascript. Let’s say you want to download Codesource.io’s logo. Download File In order to download a file, you can use the HTML’s download attribute. Note: The HTML’s download attribute functions by downloading the supplied file URL upon clicking.

March 6, 2021 in Code examples

How to Validate Email in Javascript

In this article, you will learn how to validate an email in Javascript. Validate Email In order to validate email, you can use the regular expression and test() method. Note: The regular expression is a sequence of characters used as a search pattern. The test() method functions by testing for a match in the supplied […]

March 6, 2021 in Code examples

How to Check For Array Equality in Javascript

In this article, you will learn how to check for array equality in Javascript. Let’s say you have 3 arrays. Check For Array Equality In order to check for array equality, you can use the Array.length property and Array.every() method. Note: The Array.length property functions by returning the length of the array. The Array.every() method […]

March 6, 2021 in Code examples

Using Spread Operators In Javascript

In this article, you will learn how to use spread operators in JavaScript. The spread operator basically allows iterable operations such as an array or object to be expanded in other places. Say we have two Arrays array1 and array2 We can use spread operators to merge the two arrays: Aside merging the two arrays […]

March 2, 2021 in Code examples

Compare Objects in lodash

In this article, you will learn how to compare objects in lodash. Lodash is basically a JavaScript library that provides utility functions for functional programming. Comparing objects with lodash can be achieved using the _.isEqual method. Here’s how: This returns false if objects are different.

March 2, 2021 in Code examples
Deven
Deven wrote

How to Implement Block scope in JavaScript

In this article, you will learn How to Implement Block scope in JavaScript. Block scope is a new ES6 feature. You create a new block scope for each set of curly braces. you use let and const keywords to add Variables to block scope. Implement Block scope in JavaScript Consider the example below: To implement block scope in JavaScript with […]

February 24, 2021 in Code examples