Articles on Trending Technologies

Technical articles with clear explanations and examples

How does the browser identify inline JavaScripts?

Johar Ali
Johar Ali
Updated on 15-Mar-2026 504 Views

When HTML contains JavaScript code directly within HTML elements or script tags, browsers use specific mechanisms to identify and execute this inline JavaScript. Event Handler Attributes Browsers automatically detect JavaScript in HTML event attributes like onclick, onload, onmouseover, etc., even without explicit tags. Inline JavaScript Example Hover over this text In this example, the browser identifies JavaScript code in ...

Read More

What are the rules for JavaScript's automatic semicolon insertion (ASI)?

Amit Sharma
Amit Sharma
Updated on 15-Mar-2026 402 Views

JavaScript's automatic semicolon insertion (ASI) is a feature that automatically inserts missing semicolons in your code. Understanding ASI rules helps prevent unexpected behavior and syntax errors. Statements Affected by ASI The following JavaScript statements are affected by automatic semicolon insertion: empty statement var statement expression statement do-while statement continue statement break statement return statement throw statement Core ASI Rules JavaScript follows these rules when deciding where to insert semicolons: Rule 1: Offending Token A semicolon is inserted before a token that cannot be parsed according to grammar rules, if: ...

Read More

How to handle when JavaScript is turned off?

Johar Ali
Johar Ali
Updated on 15-Mar-2026 188 Views

When JavaScript is disabled in a browser, web pages may lose functionality or display incorrectly. The HTML tag provides a fallback solution by displaying alternative content when JavaScript is unavailable or turned off. What is the noscript Tag? The tag defines content that should be displayed only when JavaScript is disabled or not supported by the browser. This tag helps ensure your website remains accessible to all users, regardless of their JavaScript settings. Syntax Basic Example JavaScript ...

Read More

JavaScript function in href vs. onClick

Amit Sharma
Amit Sharma
Updated on 15-Mar-2026 13K+ Views

When creating clickable links that execute JavaScript, you can use either the href attribute with a JavaScript URL or the onclick event handler. Each approach has different behaviors and use cases. Using href with JavaScript The href attribute can execute JavaScript using the javascript: protocol. However, this approach has limitations with rapid clicks and can interfere with browser navigation. JavaScript href Example function calculateSum() { ...

Read More

How to declare variables in JavaScript?

Rahul Sharma
Rahul Sharma
Updated on 15-Mar-2026 1K+ Views

Like many other programming languages, JavaScript has variables. Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container. Before you use a variable in a JavaScript program, you must declare it. JavaScript provides three ways to declare variables: var, let, and const. Using var Keyword Variables are declared with the var keyword as follows: var money; var name; You can also declare multiple variables with the same var keyword: ...

Read More

What is the difference between window.onload and document.onload in Javascript?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 2K+ Views

In JavaScript, window.onload and document.onload handle different loading stages of a web page. Understanding their timing differences is crucial for proper DOM manipulation and event handling. document.onload The document.onload event fires when the HTML document has been completely loaded and parsed, but before images, stylesheets, and other external resources finish loading. However, document.onload is not widely supported across browsers. Instead, use DOMContentLoaded event for similar functionality. window.onload The window.onload event fires when the complete page has loaded, including all images, scripts, CSS files, and other external content. This ensures all resources are available before your code ...

Read More

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

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

When building web applications, you can include JavaScript code either inline within HTML or as external files. Each approach has specific use cases and performance implications. External JavaScript Files (Recommended) External JavaScript files offer better performance and maintainability. Browsers can cache external files, reducing load times for subsequent visits. Create a JavaScript file with .js extension and link it using the src attribute: // new.js function display() { alert("Hello World!"); } Include the external file in your HTML: ...

Read More

What is the difference between anonymous and inline functions in JavaScript?

Rahul Sharma
Rahul Sharma
Updated on 15-Mar-2026 2K+ Views

In JavaScript, anonymous and inline functions are closely related concepts that are often confused. Let's explore their differences and uses. Anonymous Functions Anonymous functions are functions without a name identifier. They are created at runtime and cannot be called directly by name. Here's how they work: // Anonymous function assigned to a variable var myfunc = function() { alert('This is anonymous'); }; Anonymous functions are commonly used as arguments to other functions: setTimeout(function() { alert('Demo'); }, 3000); Inline Functions An inline ...

Read More

How to write JavaScript in an External File?

Amit Sharma
Amit Sharma
Updated on 15-Mar-2026 8K+ Views

JavaScript code can be written in external files with a .js extension and included in HTML documents using the tag's src attribute. This approach improves code organization and reusability. Why Use External JavaScript Files? External JavaScript files offer several advantages: Code Reusability: Same file can be used across multiple HTML pages Better Organization: Keeps HTML and JavaScript code separated Caching: Browsers cache external files, improving page load times Maintainability: Easier to update and debug code Creating an External JavaScript File First, create a JavaScript file with the .js extension. For example, script.js: ...

Read More

Why prefer to put JavaScript in the footer of an HTML page?

Rahul Sharma
Rahul Sharma
Updated on 15-Mar-2026 938 Views

JavaScript can be placed anywhere in an HTML page, whether inside the or tag. However, it's considered best practice to place JavaScript in the footer, just before the closing tag. Why Place JavaScript in the Footer? Non-blocking page rendering: Scripts don't block HTML content from loading DOM availability: All HTML elements are already parsed and available Faster perceived load time: Users see content immediately Better user experience: Page appears responsive during script loading Improved performance: Critical rendering path is ...

Read More
Showing 19171–19180 of 61,297 articles
Advertisements