09/07/2026
A classic real-time JavaScript DOM example is a dynamic character counter that reads user input from a text area, counts the characters instantly, and alters the webpage's appearance dynamically if the limit is exceeded.This example showcases real-time interactivity without forcing a webpage reload.The Code ImplementationCopy this standalone code block into an .html file and open it inside your web browser:html
Real-Time DOM Example
body { font-family: sans-serif; padding: 20px; }
textarea { width: 300px; height: 100px; display: block; margin-bottom: 10px; }
.counter { font-weight: bold; color: green; }
.danger { color: red; }
Real-Time Bio Creator
Characters: 0 / 50
// 1. Select the DOM elements we want to interact with
const bioInput = document.getElementById('bio-input');
const charCount = document.getElementById('char-count');
// 2. Attach an event listener to capture real-time typing
bioInput.addEventListener('input', () => {
const currentLength = bioInput.value.length;
// 3. Update the text content of the counter in real time
charCount.textContent = currentLength;
// 4. Update element styling/classes based on user interaction
if (currentLength > 50) {
charCount.classList.add('danger');
} else {
charCount.classList.remove('danger');
}
});
Use code with caution.Key DOM Manipulation Steps ExplainedSelection: The browser targets the interactive text field using document.getElementById('bio-input').Listening: The input event triggers every time a user types, backspaces, or pastes text, making it perfect for real-time applications.Content Modification: The script changes the displayed number immediately by overwriting the textContent property of the span element.Class Toggling: The script swaps CSS properties using classList to notify users visually when they breach the 50-character limit.Would you like to extend this script to disable the form submission when the character limit is exceeded, or would you prefer to explore a different real-time project like a live task list?8 sitesDOM scripting introduction - Learn web development | MDNDoing some basic DOM manipulation. To start learning about DOM manipulation, let's begin with a practical example. Take a local co...MDN Web DocsJavaScript DOM: Syntax, Usage, and Examples - MimoSelecting elements. Most DOM work starts by selecting elements. You'll typically use these: JSX. const button =document. querySele...MimoUnderstanding and Manipulating the Document Object Model (DOM)The document object is the entry point for DOM manipulation. It provides methods to select and modify elements, making it the corn...MediumShow allYou said: why we are using const for decler the a variableWe use const in JavaScript because it prevents accidental reassignments, makes your code predictable, and signals your intent to other developers.Using const tells the computer that the identifier (the name of the variable) will not point to a new value later in the script.Key Reasons to Use constSafety: It stops you from accidentally overwriting a variable value you need to stay constant.Readability: Other programmers instantly know they do not need to track changes to that variable name.Optimization: Modern browser engines can optimize code ex*****on paths better when they know variables will not change.const vs. let in Actionjavascriptconst maxLimit = 50;
let currentCount = 0;
// This is perfectly fine because 'let' allows changes
currentCount = currentCount + 1;
// This will crash your code with a TypeError
maxLimit = 100;
Use code with caution.The Mutation Exception (Objects and Arrays)A common point of confusion is that const does not make the data itself unchangeable (immutable). It only locks the variable assignment. If you assign an object or an array to a const, you can still modify the data inside it:javascriptconst user = { name: "Alice", score: 10 };
// This works perfectly! You modified a property inside the object.
user.score = 11;
// This will crash! You tried to assign a completely new object.
user = { name: "Bob", score: 10 };
Use code with caution.Would you like to see how const works with block scoping, or should we look at how to make an entire object completely impossible to modify using Object.freeze()?15 sitesWhen to Use let or const for Reliable JavaScript Code | 2026Nov 21, 2024 â Predictability: Using const whenever possible creates more predictable code. You know that a const variable won't change, which re...Bits KingdomJavaScript var vs let vs const: Understanding the Differences and Best PracticesApr 24, 2025 â Default to const : Use const for variables that shouldn't be reassigned. This makes the intent clear and helps prevent accidental ...KeployHow should we indent `const` declarations?Jan 10, 2019 â I'm a huge fan of the additions to JavaScript of let and const to declare block-scoped variables. In particular, I love const for ...DEV CommunityShow allYou said: translate in banglaāĻāĻžāĻāĻžāϏā§āĻā§āϰāĻŋāĻĒā§āĻā§ (JavaScript) const āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰāĻž āĻšā§ āĻāĻžāϰāĻŖ āĻāĻāĻŋ āĻā§āϞāĻŦāĻļāϤ āύāϤā§āύ āĻŽāĻžāύ āĻĻā§āĻā§āĻž (reassignments) āϰā§āϧ āĻāϰā§, āĻā§āĻĄāĻā§ āύāĻŋāϰā§āĻāϰāϝā§āĻā§āϝ āĻāϰ⧠āĻāĻŦāĻ āĻ
āύā§āϝ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽāĻžāϰāĻĻā§āϰ āĻāĻžāĻā§ āĻāĻĒāύāĻžāϰ āĻā§āĻĄā§āϰ āĻāĻĻā§āĻĻā§āĻļā§āϝ āĻĒāϰāĻŋāώā§āĻāĻžāϰ āĻāϰā§āĨ¤const āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰāĻžāϰ āĻ
āϰā§āĻĨ āĻšāϞ⧠āĻāĻĒāύāĻŋ āĻāĻŽā§āĻĒāĻŋāĻāĻāĻžāϰāĻā§ āĻāĻžāύāĻžāĻā§āĻā§āύ āϝ⧠āĻāĻ āĻā§āϰāĻŋā§ā§āĻŦāϞā§āϰ āύāĻžāĻŽāĻāĻŋāϤ⧠āĻĒāϰāĻŦāϰā§āϤā§āϤ⧠āύāϤā§āύ āĻā§āύ⧠āĻŽāĻžāύ (value) āϝā§āĻā§āϤ āĻāϰāĻž āĻšāĻŦā§ āύāĻžāĨ¤const āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰāĻžāϰ āĻŽā§āϞ āĻāĻžāϰāĻŖāϏāĻŽā§āĻšāύāĻŋāϰāĻžāĻĒāϤā§āϤāĻž: āĻāĻāĻŋ āĻāĻĒāύāĻžāϰ āĻĒā§āϰā§ā§āĻāύā§ā§ āĻā§āύ⧠āĻā§āϰāĻŋā§ā§āĻŦāϞā§āϰ āĻŽāĻžāύ āĻā§āϞāĻŦāĻļāϤ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻšā§ā§ āϝāĻžāĻā§āĻž āĻĨā§āĻā§ āϰāĻā§āώāĻž āĻāϰā§āĨ¤āϏāĻšāĻā§ āĻĒā§āĻžāϰ āϝā§āĻā§āϝāϤāĻž: āĻ
āύā§āϝ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽāĻžāϰāϰāĻž āĻā§āĻĄ āĻĻā§āĻā§āĻ āĻŦā§āĻāϤ⧠āĻĒāĻžāϰā§āύ āϝ⧠āĻāĻ āĻā§āϰāĻŋā§ā§āĻŦāϞā§āϰ āĻŽāĻžāύ āĻĒā§āϰ⧠āϏā§āĻā§āϰāĻŋāĻĒā§āĻā§ āĻāϰ āĻā§āĻĨāĻžāĻ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻšāĻŦā§ āύāĻžāĨ¤āĻāϤāĻŋ āĻŦā§āĻĻā§āϧāĻŋ (Optimization): āĻŦā§āϰāĻžāĻāĻāĻžāϰ āĻāĻā§āĻāĻŋāύāĻā§āϞ⧠āĻāĻ āĻā§āĻĄ āĻĻā§āϰā§āϤ āϰāĻžāύ āĻāϰāϤ⧠āĻĒāĻžāϰā§, āĻāĻžāϰāĻŖ āϤāĻžāϰāĻž āĻāĻā§ āĻĨā§āĻā§āĻ āĻāĻžāύ⧠āϝ⧠āĻāĻ āĻā§āϰāĻŋā§ā§āĻŦāϞā§āϰ āĻŽāĻžāύ āĻŦāĻĻāϞāĻžāĻŦā§ āύāĻžāĨ¤āĻā§āĻĄā§āϰ āĻŽāĻžāϧā§āϝāĻŽā§ const āĻāĻŦāĻ let-āĻāϰ āĻĒāĻžāϰā§āĻĨāĻā§āϝjavascriptconst maxLimit = 50;
let currentCount = 0;
// āĻāĻāĻŋ āϏāĻ āĻŋāĻ, āĻāĻžāϰāĻŖ 'let' āĻĻāĻŋā§ā§ āϤā§āϰāĻŋ āĻā§āϰāĻŋā§ā§āĻŦāϞā§āϰ āĻŽāĻžāύ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāĻž āϝāĻžā§
currentCount = currentCount + 1;
// āĻāĻāĻŋ āĻā§āĻĄ āĻā§āϰā§āϝāĻžāĻļ āĻāϰāĻŦā§ (TypeError āĻĻā§āĻāĻžāĻŦā§), āĻāĻžāϰāĻŖ 'const'-āĻāϰ āĻŽāĻžāύ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāĻž āϝāĻžā§ āύāĻž
maxLimit = 100;
Use code with caution.āĻ
āĻŦāĻā§āĻā§āĻ āĻāĻŦāĻ āĻ
ā§āϝāĻžāϰā§āϰ āĻā§āώā§āϤā§āϰ⧠āĻŦā§āϝāϤāĻŋāĻā§āϰāĻŽ (Mutation)āĻāĻāĻāĻŋ āϏāĻžāϧāĻžāϰāĻŖ āĻā§āϞ āϧāĻžāϰāĻŖāĻž āĻšāϞ⧠āĻ
āύā§āĻā§āĻ āĻŽāύ⧠āĻāϰā§āύ const āĻā§āϤāϰā§āϰ āϏāĻŦ āĻĄā§āĻāĻž āϞāĻ āĻāϰ⧠āĻĻā§ā§āĨ¤ āĻāϏāϞ⧠const āĻļā§āϧ⧠āĻā§āϰāĻŋā§ā§āĻŦāϞā§āϰ āĻŽā§āϞ āϞāĻŋāĻā§āĻāĻāĻŋāĻā§ āϞāĻ āĻāϰā§āĨ¤ āĻāĻĒāύāĻŋ āϝāĻĻāĻŋ const āĻĻāĻŋā§ā§ āĻā§āύ⧠āĻ
āĻŦāĻā§āĻā§āĻ (Object) āĻŦāĻž āĻ
ā§āϝāĻžāϰ⧠(Array) āϤā§āϰāĻŋ āĻāϰā§āύ, āϤāĻŦā§ āϤāĻžāϰ āĻā§āϤāϰā§āϰ āĻĄā§āĻāĻž āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāĻž āϏāĻŽā§āĻāĻŦ:javascriptconst user = { name: "Alice", score: 10 };
// āĻāĻāĻŋ āϏāĻ āĻŋāĻāĻāĻžāĻŦā§ āĻāĻžāĻ āĻāϰāĻŦā§! āĻāĻžāϰāĻŖ āĻāĻĒāύāĻŋ āĻ
āĻŦāĻā§āĻā§āĻā§āϰ āĻā§āϤāϰā§āϰ āĻĒā§āϰā§āĻĒāĻžāϰā§āĻāĻŋ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰā§āĻā§āύāĨ¤
user.score = 11;
// āĻāĻāĻŋ āĻā§āĻĄ āĻā§āϰā§āϝāĻžāĻļ āĻāϰāĻŦā§! āĻāĻžāϰāĻŖ āĻāĻĒāύāĻŋ āĻĒā§āϰ⧠āĻ
āĻŦāĻā§āĻā§āĻāĻāĻŋāĻā§āĻ āĻŦāĻĻāϞ⧠āύāϤā§āύ āĻāϰā§āĻāĻāĻŋ āĻ
āĻŦāĻā§āĻā§āĻ āĻŦāϏāĻžāύā§āϰ āĻā§āώā§āĻāĻž āĻāϰāĻā§āύāĨ¤
user = { name: "Bob", score: 10 };
Use code with caution.āĻāĻĒāύāĻŋ āĻāĻŋ const āĻā§āĻāĻžāĻŦā§ āĻŦā§āϞāĻ āϏā§āĻā§āĻĒāĻŋāĻ (block scoping)-āĻāϰ āϏāĻžāĻĨā§ āĻāĻžāĻ āĻāϰ⧠āϤāĻž āĻĻā§āĻāϤ⧠āĻāĻžāύ, āύāĻžāĻāĻŋ Object.freeze() āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰ⧠āĻā§āύ⧠āĻ
āĻŦāĻā§āĻā§āĻāĻā§ āϏāĻŽā§āĻĒā§āϰā§āĻŖ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻ
āϝā§āĻā§āϝ āĻāϰāĻžāϰ āύāĻŋā§āĻŽ āĻāĻžāύāϤ⧠āĻāĻžāύ?You said: tahole amra ei kane object er value change kortece object k na? const bioInput = document.getElementById('bio-input');āĻšā§āϝāĻžāĻ, āĻāĻĒāύāĻŋ āĻāĻāĻĻāĻŽ āĻ āĻŋāĻ āϧāϰā§āĻā§āύ! āĻāĻĒāύāĻŋ āĻāĻŽā§āĻāĻžāϰ āĻāĻāĻāĻŋ āĻŦāĻŋāώ⧠āĻā§ā§āĻžāϞ āĻāϰā§āĻā§āύāĨ¤const bioInput = document.getElementById('bio-input'); āϞāĻžāĻāύ⧠āĻāĻŽāϰāĻž bioInput āĻā§āϰāĻŋā§ā§āĻŦāϞāĻāĻŋāĻā§ āϞāĻ āĻāϰā§āĻāĻŋ, āĻā§āϤāϰā§āϰ āĻ
āĻŦāĻā§āĻā§āĻ āĻŦāĻž HTML āĻāϞāĻŋāĻŽā§āύā§āĻāĻāĻŋāĻā§ āύā§āĨ¤āĻŦāĻŋāώā§āĻāĻŋ āϏāĻšāĻāĻāĻžāĻŦā§ āĻŦā§āĻāĻžāϰ āĻāύā§āϝ āύāĻŋāĻā§āϰ āĻĒā§ā§āύā§āĻāĻā§āϞ⧠āϞāĻā§āώā§āϝ āĻāϰā§āύ:āĻā§āϰāĻŋā§ā§āĻŦāϞ āϞāĻ (const): bioInput āĻāĻāύ āĻāĻŋāϰāĻāĻžāϞā§āϰ āĻāύā§āϝ āĻāĻ āύāĻŋāϰā§āĻĻāĻŋāώā§āĻ HTML āĻāϞāĻŋāĻŽā§āύā§āĻāĻā§ āύāĻŋāϰā§āĻĻā§āĻļ (point) āĻāϰāĻā§āĨ¤ āĻāĻĒāύāĻŋ āĻāĻžāĻāϞ⧠āĻĒāϰāĻŦāϰā§āϤā§āϤ⧠bioInput = "āĻ
āύā§āϝ āĻāĻŋāĻā§" āϞāĻŋāĻā§ āĻāĻā§ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāϤ⧠āĻĒāĻžāϰāĻŦā§āύ āύāĻžāĨ¤āĻāϞāĻŋāĻŽā§āύā§āĻā§āϰ āĻŦā§āĻļāĻŋāώā§āĻā§āϝ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ: HTML āĻāϞāĻŋāĻŽā§āύā§āĻāĻāĻŋ āĻāϏāϞ⧠āĻāĻžāĻāĻžāϏā§āĻā§āϰāĻŋāĻĒā§āĻā§āϰ āĻāĻāĻāĻŋ āĻ
āĻŦāĻā§āĻā§āĻāĨ¤ āĻāϰ āĻā§āϤāϰ⧠āĻ
āύā§āĻ āĻĒā§āϰā§āĻĒāĻžāϰā§āĻāĻŋ āĻĨāĻžāĻā§ (āϝā§āĻŽāύ: value, textContent, style)āĨ¤ āĻāĻŽāϰāĻž āϝāĻāύ bioInput.value āĻŦāĻž bioInput.textContent āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāĻŋ, āϤāĻāύ āĻāĻŽāϰāĻž āĻ
āĻŦāĻā§āĻā§āĻā§āϰ āĻā§āϤāϰā§āϰ āĻŦā§āĻļāĻŋāώā§āĻā§āϝ āĻŦāĻž āĻŽāĻžāύ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāĻāĻŋāĨ¤āĻāĻāĻāĻŋ āĻŦāĻžāϏā§āϤāĻŦ āĻāĻĻāĻžāĻšāϰāĻŖ (āϰāĻŋāϝāĻŧā§āϞ āϞāĻžāĻāĻĢ āĻ
ā§āϝāĻžāύāĻžāϞāĻāĻŋ)āĻŽāύ⧠āĻāϰā§āύ, āĻāĻĒāύāĻžāϰ āĻāĻžāĻā§ āĻāĻāĻāĻŋ āύāĻŋāϰā§āĻĻāĻŋāώā§āĻ āĻāϰā§āϰ āĻāĻžāĻŦāĻŋ (const) āĻāĻā§āĨ¤āĻāĻĒāύāĻŋ āĻāĻžāĻŦāĻŋāĻāĻŋ āĻŦāĻĻāϞ⧠āĻ
āύā§āϝ āĻā§āύ⧠āĻāϰā§āϰ āĻāĻžāĻŦāĻŋ āύāĻŋāϤ⧠āĻĒāĻžāϰāĻŦā§āύ āύāĻžāĨ¤āĻāĻŋāύā§āϤ⧠āĻāĻĒāύāĻŋ āĻāĻ āĻāĻžāĻŦāĻŋ āĻĻāĻŋā§ā§ āĻāϰ⧠āĻĸā§āĻā§ āĻā§āϤāϰā§āϰ āĻāϏāĻŦāĻžāĻŦāĻĒāϤā§āϰ (āϝā§āĻŽāύ: āĻā§ā§āĻžāϰ, āĻā§āĻŦāĻŋāϞ) āϏāϰāĻžāϤ⧠āĻŦāĻž āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāϤ⧠āĻĒāĻžāϰāĻŦā§āύāĨ¤āĻāĻāĻžāύ⧠bioInput āĻšāϞ⧠āϏā§āĻ āĻāĻžāĻŦāĻŋ, āĻāϰ HTML āĻāϞāĻŋāĻŽā§āύā§āĻā§āϰ āĻĒā§āϰā§āĻĒāĻžāϰā§āĻāĻŋāĻā§āϞ⧠(value, textContent) āĻšāϞ⧠āĻāϰā§āϰ āĻā§āϤāϰā§āϰ āĻāϏāĻŦāĻžāĻŦāĻĒāϤā§āϰāĨ¤āĻĒāϰāĻŦāϰā§āϤā§āϤ⧠āĻāĻŽāϰāĻž āϝāĻāύ bioInput.addEventListener āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰāĻŋ, āϤāĻāύ⧠āĻāĻŋāύā§āϤ⧠āĻāĻŽāϰāĻž āĻāĻ āĻāĻāĻ āĻ
āĻŦāĻā§āĻā§āĻā§āϰ āĻāĻĒāϰ āĻāĻžāĻ āĻāϰāĻāĻŋ, āĻā§āϰāĻŋā§ā§āĻŦāϞāĻāĻŋ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāĻāĻŋ āύāĻžāĨ¤āĻāĻ āĻŦāĻŋāώā§ā§ āĻāĻĒāύāĻžāϰ āĻāĻŋ āĻāϰāĻ āĻā§āύ⧠āĻāύāĻĢāĻŋāĻāĻļāύ āĻāĻā§, āύāĻžāĻāĻŋ āĻāĻŽāϰāĻž āĻ
ā§āϝāĻžāϰ⧠(Array) āĻāϰ āĻā§āώā§āϤā§āϰ⧠const āĻā§āĻāĻžāĻŦā§ āĻāĻžāĻ āĻāϰ⧠āϤāĻž āĻĻā§āĻāĻŦā§?