Found 6710 Articles for Javascript

Extract a number from a string using JavaScript

Shubham Vora
Updated on 14-Sep-2023 15:57:17

37K+ Views

In JavaScript, there are multiple ways to extract a number from a string. One way is to use the match() method and a regular expression to search for all numeric digits in the string. Another way is to use the replace() method and a regular expression to remove all nonnumeric characters from the string, leaving only the numbers. Let’s understand each of the methods with the help of some examples. Using the match() method and regular expression The regular expression is one kind of search pattern which we can create by combining multiple alphabetic and special characters. We can ... Read More

Explain the different ready states of a request in AJAX

Shubham Vora
Updated on 05-Jan-2023 16:07:08

2K+ Views

AJAX stands for Asynchronous JavaScript and XML. It is a set of web development techniques to create interactive web applications. AJAX allows a web page to communicate with a server without reloading the page. Ready states are an important part of working with AJAX requests. The ready state of a request indicates the request’s status to the server and allows the client to track the progress of the request. In the below, we detailed the different ready states of AJAX. UNSENT STATE (0) This is the first ready state of the AJAX. It is denoted by the integer 0. When ... Read More

Explain the working of timers in JavaScript

Shubham Vora
Updated on 05-Jan-2023 16:05:23

669 Views

In JavaScript, timers are a very noteworthy feature. As like the normal watch timer, we can start the timer at a time and execute the function or code in JavaScript after a particular time. In simple terms, we can use the timer to execute the code after some delay. For example, when you visit some website, it shows the signup box after 3 to 4 minutes of your visit, and that we can achieve using JavaScript. We can set the delay timer to show the signup popup box. Another good example of the timer in real life is ads ... Read More

Explain the differences in the usage of foo between function foo() {} and var foo = function() {}

Shubham Vora
Updated on 05-Jan-2023 16:03:33

1K+ Views

In JavaScript, we have different ways to define the functions. The function foo() {} and var foo = function() { } is two different ways to define the function. Both ways have their benefits and different use cases; however, both give the same result when executing the function. So, this tutorial will teach us the difference between both ways to define a function. Explanation of the function foo() { }: function declaration The function foo() { } is the normal way to declare the function in JavaScript, which every beginner and developer uses. Also, we can call it a named ... Read More

Explain the benefits of spread syntax & how it is different from rest syntax in ES6?

Shubham Vora
Updated on 05-Jan-2023 16:01:07

259 Views

In the ES6 version of JavaScript, spread syntax is introduced as a very powerful feature. We can use the spread syntax to expand the array or objects into the variable of the same data type. For example, before the spread syntax was introduced in the ES6, developers were using the for loop to copy all elements of one array to another array. Can you copy all elements of one array to another by writing one linear code using the spread syntax rather than writing the 5 to 7 lines of code using the for loop? Yes, you heard right! ... Read More

Explain Storage Object in HTML

Shubham Vora
Updated on 05-Jan-2023 15:47:25

319 Views

As the web storage word represents, it stores the data inside the user’s browser locally. Before HTML 5, developers were using cookies to store data locally, but the cookies allow for storing a limited amount of data, such as in kilobytes. The local storage allows users to store up to 5 MB of data. Developers use the cookies to store the data in the browser and exchange it between the client and server. When we store the data in the cookies, it expires after a particular time. However, we can set the data's expiry, but it still expires after ... Read More

Explain the Scope and Scope Chain in JavaScript

Shubham Vora
Updated on 05-Jan-2023 15:42:24

2K+ Views

In JavaScript, the scope defines how and in which part of our code we can access the variables and functions. In simple terms, the scope helps us improve our code's security and readability. So, we can access the variables and functions only inside its scope but not outside. We will discuss multiple types of scopes in this tutorial. Global Scope in JavaScript The variables and functions defined globally mean outside all blocks and functions with global scope. We can access all variables and functions with the global scope anywhere inside our code. Syntax Users can follow the syntax below ... Read More

How to switch off object caching for a Polygon object using FabricJS?

Rahul Gurung
Updated on 02-Jan-2023 16:15:28

584 Views

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity, etc. A FabricJS object is cached on an additional canvas for saving time during re-using the object. In order to switch off object caching for Polygon object we use the objectCaching property. Syntax new fabric.Polygon( points: Array, { objectCaching: Boolean }: Object ) Parameters ... Read More

How to straighten a rotated Polygon object using FabricJS?

Rahul Gurung
Updated on 02-Jan-2023 16:12:44

196 Views

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. We can straighten a rotated Polygon object by using the straighten method. The straighten method straightens an object by rotating it from its current angle to 0, 90, 180 or 270 etc., depending on the angle that is closer. Syntax straighten(): fabric.Object Example ... Read More

How to serialize a Polygon object using FabricJS?

Rahul Gurung
Updated on 02-Jan-2023 16:10:15

273 Views

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. Serialization is the process of converting an object into a format which is suitable for transfer over a network, which in this case is the object representation. In order to create an Object representation of a Polygon object, we use the toObject method. This method ... Read More

Advertisements