Javascript Articles

Page 519 of 534

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

How to redirect if JavaScript is not enabled in a browser?

mkotla
mkotla
Updated on 15-Mar-2026 1K+ Views

To redirect if JavaScript is not enabled in the web browser, add a script to the tag. Let us say you need to redirect to index.php if JavaScript is not enabled. The Problem When JavaScript is disabled, users might see a broken or non-functional page. The tag provides a fallback solution to redirect users to a JavaScript-free version of your site. How It Works The tag only executes when JavaScript is disabled or unavailable. We can use it with CSS and meta refresh to redirect users seamlessly. Example Here's how you ...

Read More

How to find whether a browser supports JavaScript or not?

vanithasree
vanithasree
Updated on 15-Mar-2026 1K+ Views

To find whether a browser supports JavaScript or not, use the tag. The HTML tag is used to handle browsers which recognize the tag but do not support scripting. This tag displays an alternate message when JavaScript is disabled or unsupported. Using the Tag The element provides fallback content that displays only when JavaScript is unavailable. Content inside is hidden when JavaScript is enabled. JavaScript Support Detection document.write("JavaScript ...

Read More

How to detect if JavaScript is disabled in a browser?

radhakrishna
radhakrishna
Updated on 15-Mar-2026 7K+ Views

To detect if JavaScript is disabled in a web browser, you can use several approaches. The most common method is the HTML tag, which displays content only when JavaScript is unavailable. Using the Tag The tag provides fallback content for browsers that don't support JavaScript or have it disabled: JavaScript Detection document.write("JavaScript is enabled!"); ...

Read More

How to give a warning for Non-JavaScript Browsers?

Giri Raju
Giri Raju
Updated on 15-Mar-2026 321 Views

To warn users about non-JavaScript browsers, use the tag. The HTML tag handles browsers that recognize tags but have JavaScript disabled or don't support scripting. This tag displays alternate content when JavaScript is unavailable. Syntax Content to display when JavaScript is disabled Basic Example Here's how to provide a warning message for users without JavaScript: JavaScript Warning Example document.write("Hello JavaScript!"); ...

Read More
Showing 5181–5190 of 5,340 articles
« Prev 1 517 518 519 520 521 534 Next »
Advertisements