Front End Technology Articles

Page 16 of 652

What is the difference between “lang” and “type” attributes in a script tag?

Arushi
Arushi
Updated on 11-Mar-2026 334 Views

JavaScript lang attributeThis attribute specifies what scripting language you are using. Typically, its value will be javascript. Although recent versions of HTML (and XHTML, its successor) have phased out the use of this attribute.JavaScript type attributeThis attribute is what is now recommended to indicate the scripting language in use and its value should be set to "text/javascript".Here you can see how it is used:                              

Read More

When should I use an Inline script and when to use external JavaScript file?

Sai Subramanyam
Sai Subramanyam
Updated on 11-Mar-2026 2K+ Views

To enhance performance, try to keep JavaScript external. The separate code makes it easier for web browsers to cache. However, use inline scripts only when you’re making single page websites. Still, it's better to use external code i.e. external JavaScript. To place JavaScript in external file create an external JavaScript file with the extension .js. After creating, add it to the HTML file in the script tag. The src attribute is used to include that external JavaScript file. If you have more than one external JavaScript file, then add it to the same web page to increase the performance of ...

Read More

What are generator functions in JavaScript?

Prabhas
Prabhas
Updated on 11-Mar-2026 328 Views

Generator Functions allows execution of code in between when a function is exited and resumed later. So, generators can be used to manage flow control in a code. Cancel asynchronous operations easily since execution can be paused anytime.Here’s the syntax; do not forget to add an asterisk after the “function” keyword. You can add an asterisk using any of the following −function *myFunction() {} // or function* myFunction() {} // or function*myFunction() {}ExampleLet’s see how to use a generator function                    function* display() {             var ...

Read More

Usage of rest parameter and spread operator in JavaScript?

Anjana
Anjana
Updated on 11-Mar-2026 381 Views

Rest ParameterWith rest parameter, you can represent a number of arguments as an array. ES6 brought rest parameter to ease the work of developers. For arguments objects, rest parameters are indicated by three dots … and precedes a parameter.Let’s see the following code snippet to define rest parameter −                    function addition(…numbers) {             var res = 0;             numbers.forEach(function (number) {                res += number;             });     ...

Read More

What are the latest operators added to JavaScript?

Ayyan
Ayyan
Updated on 11-Mar-2026 148 Views

The latest operators added to JavaScript are spread operator and rest.Rest operatorWith rest parameter, you can represent number of arguments as an array. ES6 brought rest parameter to ease the work of developers. For arguments objects, rest parameters are indicated by three dots … and preceds a parameter.ExampleLet’s see the following code snippet to define rest parameter                    function addition(…numbers) {             var res = 0;             numbers.forEach(function (number) {                res += number;   ...

Read More

How to define getter and setter functions in JavaScript?

Ayyan
Ayyan
Updated on 11-Mar-2026 355 Views

GetterWhen a property is accessed, the value gets through calling a function implicitly. The get keyword is used in JavaScript. An identifier, either a number or a string is allowed for set.SetterWhen a property is set, it implicitly call a function and the value is passed as an argument. With that the return value is set to the property itself. The set keyword is used in JavaScript. An identifier, either a number or a string is allowed for set.ExampleHere’s an example showing how to implement both getter and setter                    var ...

Read More

How to delete a setter using the delete operator in JavaScript?

Manikanth Mani
Manikanth Mani
Updated on 11-Mar-2026 289 Views

To delete a setter using the delete operator, use the delete keyword. Here’s how you can delete −delete obj.nameExampleYou can try to run the following code to learn how to delete a setter                    var department = {             deptName: "Marketing",             deptZone: "North",             deptID: 101,             get details() {                return "Department Details" + "Name: " + this.deptName + " Zone: " + ...

Read More

What is the difference between getter and setter in JavaScript?

Akshaya Akki
Akshaya Akki
Updated on 11-Mar-2026 1K+ Views

GetterWhen a property is accessed, the value gets through calling a function implicitly. The get keyword is used in JavaScript. An identifier, either a number or a string is allowed for set.SetterWhen a property is set, it implicitly calls a function and the value is passed as an argument. With that, the return value is set to the property itself. The set keyword is used in JavaScript. An identifier, either a number or a string is allowed for set.ExampleHere’s an example showing how to implement both getter and setter                    var ...

Read More

What is the JavaScript version of sleep()?

Alankritha Ammu
Alankritha Ammu
Updated on 11-Mar-2026 462 Views

The JavaScript version of sleep() is “await”. The await feature pauses the current aync function.ExampleYou can try to run the following code to implement sleep in JavaScript                    function setSleep(ms) {             return new Promise(resolve => setTimeout(resolve, ms));          }          async function Display() {             document.write('Wait for 5 seconds!');             await setSleep(5000);             document.write('After 5 seconds!');          }          Display();          

Read More

How to Scroll to the top of the page using JavaScript/ jQuery?

Anjana
Anjana
Updated on 11-Mar-2026 309 Views

Example                    $("a").click(function() {             $("html, body").animate({ scrollTop: 0 }, "slow");             return false;          });             TOP OF PAGE             This is demo text.       This is demo text.       This is demo text.       This is demo text.       This is demo text.       This is demo text.       This is demo ...

Read More
Showing 151–160 of 6,518 articles
« Prev 1 14 15 16 17 18 652 Next »
Advertisements