JavaScript

12th April 2024

5 Different Ways to Declare Functions in jQuery

Choosing which way to declare a JavaScript function can be confusing for beginners and there are several different syntax options. Each has advantages, disadvantages, and appropriate uses that can catch you out. In this article, we examine several ways to define a block of JavaScript functionality. 1. Regular JavaScript Functions The first and most obvious way to declare a function in JavaScript is to use a function declaration. A function named multiply(), which takes two parameters x and y, multiplies them, and returns the value can be implemented with the following syntax: Functions defined in this way (a function declaration) are hoisted to the top of the current […]
10th October 2022

Quick Tip : How to Use the Spread Operator in JavaScript

Symbolized by three dots (...), the JavaScript spread operator was introduced in ES6. It can be used to expand elements in collections and arrays into single, individual elements The spread operator can be used to create and clone arrays and objects, pass arrays as function parameters, remove duplicates from arrays, and more Syntax The spread operator can only be used on iterable objects. It must be used right before the iterable object, without any separation. For example: Function Parameters Take as an example the Math.min() method. This method accepts at least one number as a parameter and returns the smallest […]
17th May 2022

Useful TypeScript and JavaScript shorthands to know

JavaScript and TypeScript share a number of useful shorthand alternatives for common code concepts. Shorthand code alternatives can help reduce lines of code, which is something we typically strive for. In this article, we will review common TypeScript and JavaScript shorthands. We will also explore examples of how to use these shorthands. JavaScript and TypeScript shorthands Using shorthand code is not always the right decision when writing clean and scalable code. Concise code can sometimes be more confusing to read and update. It is important that your code is legible and conveys meaning and context to other developers. Our decision to […]