Found 10711 Articles for Web Development

JavaScript closures vs. anonymous functions

usharani
Updated on 12-Sep-2019 07:51:45

438 Views

Anonymous FunctionsAnonymous, as the name suggests, allows creating a function without any names identifier. It can be used as an argument to other functions. They are called using the variable name:This is how JavaScript anonymous functions can be used:var func = function() {    alert(‘This is anonymous'); } func();Another example can be the following:setTimeout(function() {    alert('Demo'); }, 3000);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 example:           ... Read More

What is the difference between call and apply in JavaScript?

varun
Updated on 02-Jan-2020 09:02:51

250 Views

In JavaScript, .call and .apply are considered a method of function object..call methodCount the number of arguments with call method. It accepts one or more arguments as objects.Here’s the syntax:.call(object, “argument1”, “argument2”);.apply method To use an array as an argument, use .apply. It requires an array as its 2nd argument.Here’s the syntax:.apply(object, [“argument1”, “argument[]”]);ExampleLet’s see an example showing both call and apply method:                                 var p = {                q: "Hello"             } ... Read More

When is a CDATA section necessary within a script tag?

Prabhas
Updated on 12-Sep-2019 07:56:43

555 Views

To avoid parsing the symbols &, it is added in …. It is not needed in HTML. Let us see how CDATA is added in tags:    // Note: CDATA is now deprecated. Do not use.The CDATA Section interface is used within XML for including extended portions of text. This text is unescaped text, like < and & symbols. These symbols do not want to escape.It is used like this:

What is the !! (not not) operator in JavaScript?

seetha
Updated on 12-Sep-2019 07:57:44

412 Views

The double negation(!! ) operator is the! Operator twice and calculates the truth value of a value. It returns a Boolean value, which depends on the truthiness of the expression.Consider (!!p) as !(!p), here’s an example:If p is a false value, !p is true, and !!p is false. If p is a true value, !p is false, and !!p is true.Here’s another example:0 === false is false. !!0 === false is true. !!0 === false !!parseInt("foo") === false !!1 === true !!-1 === true !!false === false !!true === true

What is the difference between Bower and npm in JavaScript?

vanithasree
Updated on 12-Sep-2019 07:59:03

126 Views

  npmnpm is generally used for managing Node.js modules and does nested dependency tree. It also works for front-end and used for developer tools like Grunt, CoffeeScript, etc.Without using nested dependencies it is difficult to avoid dependency conflicts. So, using npm has proven to be great.Whatever you add in Node is structured as modules. On using NPM for browser-side dependencies, you'll structure your code like Node.Here’s the dependency structure:project root [node_modules] -> dependency P -> dependency Q [node_modules] -> dependency P -> dependency R [node_modules] -> dependency Q [node_modules] -> dependency P -> dependency SBower Bower requires a flat dependency tree and ... Read More

How to include JavaScript in HTML Documents?

Shubham Vora
Updated on 15-Sep-2022 12:15:18

819 Views

In this tutorial, we will learn how to include JavaScript in HTML Documents. To include JavaScript in HTML Documents, use the tag. JavaScript can be implemented using JavaScript statements that are placed within the ... . You can place the tags, containing your JavaScript, anywhere within your web page, but it is normally recommended that you should keep it within the tags. We will discuss the following three approaches to include JavaScript in HTML documents − Embedding code (within head or body) Inline Code (inside any element) External file (outside the HTML file) By Embedding ... Read More

Where should I put