1. Home
  2. /
  3. JavaScript
  4. /
  5. Vanilla JS Counter

Vanilla JS Counter - JavaScript Typing CST Test

Loading…

Vanilla JS Counter — JavaScript Code

Simple counter with increment, decrement, and reset functionality.

document.addEventListener('DOMContentLoaded', () => {
	const counterEl = document.getElementById('counter');
	const incBtn = document.getElementById('increment');
	const decBtn = document.getElementById('decrement');
	const resetBtn = document.getElementById('reset');
	let count = 0;

	const updateUI = () => counterEl.textContent = `Counter: ${count}`;

	incBtn.addEventListener('click', () => { count++; updateUI(); });
	decBtn.addEventListener('click', () => { count--; updateUI(); });
	resetBtn.addEventListener('click', () => { count = 0; updateUI(); });

	updateUI();
});

JavaScript Language Guide

JavaScript is a high-level, interpreted programming language primarily used to create dynamic and interactive content on web pages. It enables client-side scripting, DOM manipulation, and integration with HTML and CSS.

Primary Use Cases

  • ▸Adding interactivity to web pages
  • ▸Manipulating the DOM and HTML elements dynamically
  • ▸Form validation and user input handling
  • ▸Creating web applications and single-page applications (SPA)
  • ▸Server-side development with Node.js

Notable Features

  • ▸Event handling and listeners
  • ▸Asynchronous programming with Promises and async/await
  • ▸Prototype-based object-oriented programming
  • ▸Dynamic typing and flexible syntax
  • ▸Extensive ecosystem of libraries and frameworks (React, Angular, Vue)

Origin & Creator

Created by Brendan Eich in 1995 at Netscape Communications.

Industrial Note

JavaScript is specialized for web interactivity, dynamic content updates, and client-side logic, but it is also widely used for server-side applications via Node.js.

More JavaScript Typing Exercises

Vanilla JavaScript Theme Toggle and CounterVanilla JS Theme ToggleVanilla JS LocalStorage CounterVanilla JS Toggle VisibilityVanilla JS Input MirrorVanilla JS Simple TabsVanilla JS AccordionVanilla JS Countdown TimerVanilla JS Modal PopupVanilla JS Dark Mode Toggle

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher