Category: JavaScript Advance

  • JavaScript:void(0)

    The void operator is used to evaluate an expression and returns the undefined. Generally, this operator is used for obtaining the undefined primitive value. It is often used with hyperlinks. Usually the browser refreshes the page or loads a new page on clicking a link. The javascript:void(0) can be used when we don’t want to refresh or load…

  • JavaScript sleep/wait

    The programming languages such as PHP and C has a sleep(sec) function to pause the execution for a fixed amount of time. Java has a thread.sleep(), python has time.sleep(), and GO has time.sleep(2*time.second). Unlike other languages, JavaScript doesn’t have any sleep() function. We can use some approaches for simulating the sleep() function in JavaScript. The features such as promises and async/await function in JavaScript helped us to use…

  • JavaScript scroll

    The onscroll event in JavaScript occurs when a scrollbar is used for an element. The event is fired when the user moves the scrollbar up or down. We can use the CSS overflow property for creating a scrollbar. In HTML, we can use the onscroll attribute and assign a JavaScript function to it. We can also use the JavaScript’s addEventListener() method and pass a scroll event to it…

  • JavaScript scope

    A scope can be defined as the region of the execution, a region where the expressions and values can be referenced. There are two scopes in JavaScript that are global and local: Global Scope: In the global scope, the variable can be accessed from any part of the JavaScript code. Local Scope: In the local scope, the variable can…

  • JavaScript date parse() method

    The parse() method in JavaScript is used to parse the specified date string and returns the number of milliseconds between the specified date and January 1, 1970. If the string does not have valid values or if it is not recognized, then the method returns NaN. The counting of milliseconds between two specified dates helps us to find the…

  • JavaScript date format

    The JavaScript date object can be used to get a year, month and day. We can display a timer on the webpage with the help of a JavaScript date object. There are many types of date formats in JavaScript: ISO Date, Short Date, and Long Date. The formats of JavaScript’s date are defined as follows: ISO date Short…

  • JavaScript date difference

    In this article, we will see how to calculate the difference between two dates by using JavaScript. If we use the right methods, then the technique of calculating the difference is straightforward. The date object is required to calculate the difference between the dates in JavaScript. The JavaScript date object can be used to get…

  • JavaScript closures

    A closure can be defined as a JavaScript feature in which the inner function has access to the outer function variable. In JavaScript, every time a closure is created with the creation of a function. The closure has three scope chains listed as follows: Let’s understand the closure by using an example. Example1 Output In the…

  • JavaScript callback

    A callback function can be defined as a function passed into another function as a parameter. Don’t relate the callback with the keyword, as the callback is just a name of an argument that is passed to a function. In other words, we can say that a function passed to another function as an argument…

  • JavaScript Set Object

    The JavaScript Set object is used to store the elements with unique values. The values can be of any type i.e. whether primitive values or object references. Syntax Parameter iterable – It represents an iterable object whose elements will be added to the new Set. Points to remember JavaScript Set Methods Let’s see the list of…