Invoke a JavaScript Function as a Function

Shubham Vora
Updated on 14-Sep-2022 13:50:14

228 Views

In this tutorial, we will learn how to invoke a JavaScript Function as a function. Functions are a set of reusable codes that perform a specific task and may return a value. In JavaScript, functions are defined by the keyword function. A function has different parts, like a function name, parameter list, function body, and return statement. A function may not have any parameters and may also not have any return statement. In JavaScript, we also have functions with no function names, called anonymous functions. Users can follow the syntax below to declare a function. // function declaration function function_name(parameter1, ... Read More

Initialize a Boolean Array in JavaScript

Shubham Vora
Updated on 14-Sep-2022 13:47:32

4K+ Views

In this tutorial, we will learn how to initialize a boolean array in JavaScript. We can initialize a boolean array in JavaScript in three ways− Using the fill() Method Using the Array from() Method Using the for Loop Using the fill() Method We can initialize a boolean array using the fill() method. The fill() method sets the static value of all array elements from the beginning index to the end index. Syntax //initialization of boolean array with fill() method let arrayName = new Array(array_length).fill(true/false); In the above syntax, we create an array with the name "arrayName" ... Read More

Include Inline JavaScript Inside an HTML Page

Shubham Vora
Updated on 14-Sep-2022 13:45:03

9K+ Views

In this tutorial, we will learn how to include inline JavaScript inside an HTML page. Include inline JavaScript using onclick Event Just like an alert message showing up from the inline JavaScript inside an HTML page, we can also declare a function and call it. This method enabled us to write multiline code inside of a JavaScript function to do more tasks than just an alert message showing. In this example, we will change an element's text and background color by invoking a function from inline JavaScript code. Users can follow the syntax below to include inline JavaScript inside an ... Read More

Prevent Duplicate JavaScript Variables Declaration

Shubham Vora
Updated on 14-Sep-2022 13:42:57

1K+ Views

In this tutorial, we will look at a few ways to prevent duplicate JavaScript variable declarations and comparison between them from understanding which one is suitable in a given context. The best way to prevent duplicate variable declaration is to avoid creating global variables. Let’s move forward to discuss this. Wrapping Code Within a Function Here, the variables declared inside the function are not accessible outside the function and vice versa. Users can follow the syntax below for using this method. Syntax (function(){ var varNam = "test"; }()) Here varNam is wrapped inside a function. Example ... Read More

Perform Numeric Sort in JavaScript

Shubham Vora
Updated on 14-Sep-2022 13:39:30

12K+ Views

In this tutorial, we will learn how to perform the numeric Sort in JavaScript. We can arrange the given numerical values by numerical sorting into ascending or descending order In JavaScript, we use the sort () method to sort numerical values. This method sorts the arrays of numbers, strings, and objects. It sorts the elements of an array and changes the order of the original array's elements. The array elements are cast to strings to determine the order and then compared and sorted. arr.sort() Where arr is the array of numeric elements that need to be sorted, this method ... Read More

Perform Integer Division and Get Remainder in JavaScript

Shubham Vora
Updated on 14-Sep-2022 13:38:18

2K+ Views

In this tutorial, we will learn how to perform integer division and get the remainder in JavaScript. The division operator (/) returns the quotient of its operands, where the dividend is on the left, and the divisor is on the right. When another splits one operand, the remainder operator (%) returns the residual. It always takes the dividend sign. In the operation x% y, x is known as the dividend, and y is known as the divisor. If one of the operands is NaN, x is Infinity, or y is 0, the operation returns NaN. Otherwise, the dividend x is ... Read More

Load Previous URL in JavaScript History List

Shubham Vora
Updated on 14-Sep-2022 13:33:47

6K+ Views

In this tutorial, we will learn to load the previous page in the history list in JavaScript. The Window object in JavaScript accesses the window in the browser. This object contains many properties and methods required to do the tasks. The Window object also retrieves the information from the browser window. There is a history stack in every browser that saves the pages visited by the user. To access this history stack, we can use the history object that is the property of the Window object. By accessing the history from the browser, we can go to the next or ... Read More

Load Next URL in History List in JavaScript

Shubham Vora
Updated on 14-Sep-2022 13:31:40

778 Views

In this tutorial, we will learn to load the next page in the history list in JavaScript. The Window object in JavaScript accesses the window in the browser. This object contains many properties and methods required to do the tasks. The Window object also retrieves the information from the browser window. There is a history stack in every browser that saves the pages visited by the user. To access this history stack, we can use the history object that is the property of the Window object. By accessing the history from the browser, we can go to the next or ... Read More

Get Hash Part of Href Attribute in JavaScript

Shubham Vora
Updated on 14-Sep-2022 13:28:28

718 Views

In this tutorial, we will learn how to get the hash part of the href attribute of an area in JavaScript. The HTML element establishes an area within an image map with predetermined clickable zones. An image map allows you to correlate geometric regions of a picture with hypertext links. This element can only be used within the < map> element. The href property gives the area's hyperlink target. The element is not a hyperlink if the href attribute is not present. Following is a method used to get the href attribute’s hash part of an area in ... Read More

Shift Baseline of Individual Characters in Text Using Fabric.js

Rahul Gurung
Updated on 14-Sep-2022 11:38:58

360 Views

In this tutorial, we are going to learn how to shift the baseline of individual characters in Text using FabricJS. We can display text on canvas by adding an instance of fabric.Text. Not only does it allow us to move, scale and change the dimensions of the text but it also provides additional functionality like text alignment, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. Similarly, we can also shift the baseline of individual characters by using the deltaY property. Syntax new fabric.Text(text: String , { styles: { deltaY: Number}:Object }: Object) ... Read More

Advertisements