Found 10711 Articles for Web Development

How to preserve variables in a JavaScript closure function?

Shubham Vora
Updated on 20-Oct-2022 07:34:57

985 Views

In this tutorial, we will look at the method to preserve variables in a JavaScript closure function. What is a closure function? A closure function gives access to the scope of an outer function from an inner function. It also allows private variables. Closure variables are stored in stack and heap. When a function is created, closure is also created. Closure remembers external things used in it. Closures are the primary mechanism for data privacy. One drawback is that the variables used are not garbage collected. Overuse of closure functions will damage the system due to redundant ... Read More

Why are parenthesis used to wrap a JavaScript function call?

Rishi Rathor
Updated on 16-Jun-2020 11:12:24

4K+ Views

In JavaScript, the functions wrapped with parenthesis are called “Immediately Invoked Function Expressions" or "Self Executing Functions.The purpose of wrapping is to namespace and control the visibility of member functions. It wraps code inside a function scope and decrease clashing with other libraries. This is what we call Immediately Invoked Function Expression (IIFE) or Self Executing Anonymous Function.Here’s the syntax −(function() {    // code })();As you can see above, the following pair of parentheses converts the code inside the parentheses into an expression −function(){...}In addition, the next pair, i.e. the second pair of parentheses continues the operation. It calls ... Read More

How to set Text alignment in HTML?

Sharon Christine
Updated on 29-Aug-2023 07:12:50

226K+ Views

To set text alignment in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML tag, with the CSS property text-align for the center, left, and right alignment. HTML5 do not support the align attribute of the tag, so the CSS style is used to set text alignment.Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML tag or external style sheet.ExampleYou can try to run the following code to set text ... Read More

What is the difference between closure and nested functions in JavaScript?

mkotla
Updated on 09-Jan-2020 06:52:53

797 Views

JavaScript ClosuresIn JavaScript, all functions work like closures. A closure is a function, which uses the scope in which it was declared when invoked. It is not the scope in which it was invoked.Here’s an exampleLive Demo           JavaScriptClosures                       varp = 20;             functiona(){                var p = 40;                b(function(){                   alert(p);             ... Read More

How to change font size in HTML?

Syed Javed
Updated on 31-Aug-2023 02:03:07

121K+ Views

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML tag, with the CSS property font-size. HTML5 do not support the tag, so the CSS style is used to add font size.Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML tag or external style sheet.ExampleYou can try to run the following code to change the font size in an HTML page, Live Demo     ... Read More

How to set font color in HTML?

Lokesh Badavath
Updated on 29-Aug-2023 07:35:05

153K+ Views

We use the style attribute to set the font color in HTML. The style attribute specifies an inline style for an element, with the CSS color property. The attribute is used with the HTML tag, with the CSS color property. HTML5 do not support the tag, so the CSS style is used to add font color. The tag deprecated in HTML5. Syntax text… Example In the example below, we set the font color of the text inside the tag. DOCTYPE html> HTML Font color ... Read More

How does recursion function work in JavaScript?

Shubham Vora
Updated on 22-Jul-2022 13:16:55

508 Views

This article will teach you how to create a JavaScript recursive function-a function that calls itself-using the recursion method. The process of recursion involves calling itself. Recursive functions are those that call themselves repeatedly. A condition to cease calling itself is always included in recursive functions. Otherwise, it will continue to call itself. Recursive functions are typically used to divide a large issue into smaller ones. Recursive functions are frequently found in data structures like binary trees, graphs, and algorithms like binary search and quick-sort.A recursive function is not immediately clear or simple to comprehend. You will read and comprehend ... Read More

How to create a link to send email with a subject in HTML?

Ayyan
Updated on 09-Jan-2020 06:49:01

20K+ Views

To create a link to send email, use tag, with href attribute. The mail to link is added inside the tag. To add a subject, you need to add ? and then include the subject. All this comes inside the tag.Just keep in mind to add the email address where you want to receive the email in the mail to link. Also, the spaces between words for the subject shouldn’t be space, instead include %20. This is to ensure the browser displays the text properly.ExampleYou can try to run the following code to create a link to ... Read More

Understanding function scope and context in JavaScript?

Shubham Vora
Updated on 15-Nov-2022 10:41:11

187 Views

In this tutorial, let us discuss the function scope and context in JavaScript. Functions are the building blocks of Javascript. Therefore, JavaScript is a functional programming language. Scope The 'scope' is the code space where we can define and use a variable in a function. Scopes are of four types. Global scope Global 'scope' is the default scope. A variable with global 'scope' is accessible throughout the program. Browser closing removes a global variable. Window objects can access var variables wherein they can't access the let variables. Functional or local 'scope' A function variable is accessible only with the function. ... Read More

How to call functions in JavaScript?

Ankitha Reddy
Updated on 09-Jan-2020 06:48:02

151 Views

A function is a group of reusable code which can be called anywhere in your program. This eliminates the need of writing the same code repeatedly. It helps programmers in writing modular codes.The most common way to define a function in JavaScript is by using the function keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces.Here’s an example −     To call a function somewhere later in the script, you would simply need to write the name of that function as shown in the following ... Read More

Advertisements