Tag: javascript

  • undefined vs null in javascript

    If you are from the background of a programming language like Java , you might feel that the way to represent a “no value” is through the value “null”. But Javascript has two ways to denote a “no value”. One is “undefined” Another is “null” “undefined” represents “no value” whereas “null” represents “no object” to…

  • How to find execution time in javascript?

    Let’s say you want to find out the time the code you wrote took to run. There is an easy way in javascript to do it. Just use console.time() and console.timeEnd() methods. Here is an example: In the above code I am using a variable totalTime to give a label (against which the total execution…

  • How to create Javascript modules? – a basic example

    Gone were the days when Javascript was a small kid on the block. We used it only for client side validation and petty stuff. Now it has grown bigger than many major languages and occupied the territory of server side programming as well. Javascript for a long time didn’t support modules. If you wanted to…

  • How to save time typing document.getElementById().value and document.createElement() in javascript?

    If you are using vanilla javascript , you may frequently use document.getElementById(elementid).value to retrieve the value of a html element. Also to dynamically create a html element you would use document.createElement(elementtype) You can avoid typing these manually by following a simple trick. The trick is to create a function which executes the above code and…

  • How to implement print functionality efficiently in Javascript?

    Javascript provides a very easy way to print your page. Just use window.print() and the entire page gets printed. But the problem is exactly that , the entire page gets printed. If you have a print button , the print button gets printed as well. If you want only a specific portion of your page…

  • How to connect to Google Firebase Realtime database from your javascript project?

    If you are looking to connect to a database on the cloud and you don’t want to spend any money in the initial stage , Google Firebase is an excellent choice.It has a generous free limit to get started. Also you don’t need a server to connect to their database. They provide SDKs (Software Development…

  • How to save time typing console.log() statements in Javascript?

    For a javascript developer , console.log() statement is a great companion. It helps debugging issues fast. But typing this statement can be time consuming. There are two tricks to help in reducing time , typing this statement. Trick 1: Enclose variables to print in curly braces {} . Let’s say you want to print the…

  • What is the difference between firstChild and firstChildElement in Javascript?

    I was trying to get the value of the first list item of an unordered list using “firstChild” attribute. It threw error. I tried the same using “firstElementChild” and it worked! The difference it happens to be is: “firstChild” considers text entered in between html tags as a child element too in addition to html…

  • How to build Immediately Invoked Function Expressions in Javascript?

    While I was exploring how to retrieve results from an asynchronous function in Angular , I stumbled upon a solution where the developer had used IIFE to retrieve the result : It looked like this : This was confusing at first. But after exploring IIFE the above code made sense. First lets deep dive into…