Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
What is a composite data type i.e. object in JavaScript?
A data type is known as a composite data type when it represents a number of similar or different data under a single declaration of variable i.e., a data type that has multiple values grouped together. There are mainly three types of composite data types named as below − Object Array Function In this article, we will discuss the first type of composite data type i.e. object. What is an Object? An object is a collection of properties i.e, an object can store the properties ...
Read MoreWhat is the difference between Declaring and Initializing a variable in JavaScript?
In JavaScript, declaring a variable means creating it in memory, while initializing means assigning it a value. Understanding this distinction is crucial for avoiding common bugs. What is Variable Declaration? Declaration creates a variable in the current scope and allocates memory for it. The variable exists but has no assigned value. var name; // Declaration only let age; // Declaration only const PI; // Error! const must be initialized SyntaxError: Missing ...
Read MoreCan I use a JavaScript variable before it is declared?
Yes, you can use a JavaScript variable before it is declared due to a mechanism called hoisting. However, the behavior differs significantly between var, let, and const. What is Hoisting? Hoisting is JavaScript's behavior where variable and function declarations are moved to the top of their scope during compilation. This means the JavaScript engine "sees" declarations before the code executes, but only declarations are hoisted—not initializations. Hoisting with var Variables declared with var are hoisted and initialized with undefined: var Hoisting Example ...
Read MoreHow to declare boolean variables in JavaScript?
A boolean variable in JavaScript has two values: true or false. Boolean values are essential for conditional logic, comparisons, and control flow in JavaScript applications. Syntax let variableName = true; // or false let variableName = Boolean(value); // converts value to boolean Direct Boolean Assignment The simplest way to declare boolean variables is by directly assigning true or false: Boolean variable examples: Show Boolean Values ...
Read MoreHow to declare numbers in JavaScript?
JavaScript is a dynamically typed language, meaning variables can hold any data type without explicit type declaration. You can declare number variables using var, let, or const keywords. Basic Number Declaration Here's how you can declare numbers in JavaScript: var points = 100; var rank = 5; let score = 85; const maxLevel = 10; console.log("Points:", points); console.log("Rank:", rank); console.log("Score:", score); console.log("Max Level:", maxLevel); Points: 100 Rank: 5 Score: 85 Max Level: 10 Different Number Types JavaScript supports integers, floating-point numbers, and special ...
Read MoreHow to write inline JavaScript code in HTML page?
Inline JavaScript refers to JavaScript code written directly within an HTML document using tags, rather than linking to an external JavaScript file. This approach is useful for small scripts or page-specific functionality. Syntax To write inline JavaScript, place your code between opening and closing tags: // Your JavaScript code here Example: Basic Inline JavaScript Inline JavaScript Example Welcome to My Page Click Me ...
Read MoreWhat are the differences between inline JavaScript and External file?
JavaScript code can be included in HTML documents in two ways: inline JavaScript (embedded directly in HTML) and external JavaScript files (separate .js files). Understanding their differences helps choose the right approach for your project. Inline JavaScript Inline JavaScript refers to JavaScript code that is directly embedded within an HTML document, either inside tags or within HTML event attributes. Characteristics Scripts are executed immediately as the page loads Code loads instantly with the HTML - no additional HTTP requests The async and ...
Read MoreIs it better to have one big JavaScript file or multiple light files?
When building web applications, you'll face the decision between using one large JavaScript file or splitting code into multiple smaller files. The choice depends on your project type, build process, and performance requirements. Single File Approach Combining JavaScript into one file reduces HTTP requests and simplifies deployment. This approach works well for single-page applications (SPAs) where all code is needed upfront. // Example: Combined file structure // app.bundle.js contains: // - Core utilities // - UI components // - Business logic // - Third-party libraries Benefits: Fewer HTTP requests Better compression ...
Read MoreHow page load time affects with JavaScript?
Page load time is significantly affected by JavaScript files and code execution. Poor JavaScript optimization can dramatically increase loading times, creating a negative user experience. Understanding how to optimize JavaScript delivery is crucial for web performance. How JavaScript Affects Page Load Time JavaScript can impact page performance in several ways: File Size: Large, unminified JavaScript files take longer to download Execution Time: Complex scripts block page rendering during execution Network Requests: Multiple external scripts create additional HTTP requests Parser Blocking: JavaScript execution pauses HTML parsing by default Optimization Strategies Minification Minify JavaScript ...
Read MoreHow to use the same JavaScript in multiple content pages?
To use the same JavaScript in multiple content pages, add the JavaScript code in an external JavaScript file. This approach promotes code reusability and easier maintenance across your website. Creating an External JavaScript File First, create an external JavaScript file. Let's say the following demo.js is our external JavaScript file: function display() { alert("Hello World!"); } function calculate(a, b) { return a + b; } function showMessage(message) { alert("Message: " + message); } Including External JavaScript in HTML Pages ...
Read More