JavaScript Programming · Practice by type
JavaScript Programming Programs for Practice with Output
Practice programs for every JavaScript Programming topic, each with a full solution, its real output and an explanation. Try writing each one yourself first.
- 240 questions
- 24 topics
- Answers checked on a real compiler
JavaScript Basics 10 questions
- Print a student report card in JavaScript Easy
- Simple interest and total amount in JavaScript Easy
- Celsius to Fahrenheit table in JavaScript Easy
- Swap two variables in JavaScript Easy
- Area and perimeter of a rectangle and a circle in JavaScript Easy
- Convert seconds to HH:MM:SS in JavaScript Medium
- Classify numbers as even/odd and positive/negative in JavaScript Easy
- Sum of digits of a number in JavaScript Medium
- Check leap years in JavaScript Medium
- Initials and username from a full name in JavaScript Medium
Variables: var, let and const 10 questions
- Shopping cart total with GST in JavaScript Easy
- A counter that keeps its own state in JavaScript Medium
- Multiplication table in JavaScript Easy
- Running average of test marks in JavaScript Easy
- Deep freeze a configuration object in JavaScript Hard
- Minimum, maximum and average temperature in JavaScript Medium
- First 10 Fibonacci numbers in JavaScript Easy
- Countdown with setTimeout in JavaScript Medium
- Year-by-year compound interest in JavaScript Medium
- Count vowels and consonants in JavaScript Easy
Data Types 10 questions
- Report the type of every value in an array in JavaScript Easy
- Exact factorial with BigInt in JavaScript Medium
- Exact bill total using paise in JavaScript Medium
- Validate numeric input strings in JavaScript Medium
- Deep clone vs JSON copy in JavaScript Hard
- Count values of each type in JavaScript Easy
- Decimal, binary, octal and hexadecimal table in JavaScript Easy
- Compare decimal results safely in JavaScript Medium
- Remove falsy values from an array in JavaScript Easy
- A precise type-of function in JavaScript Hard
Operators 10 questions
- Simple calculator in JavaScript Easy
- Even or odd with % and with bitwise AND in JavaScript Easy
- Swap two numbers without a third variable in JavaScript Medium
- Salary slip with compound assignment in JavaScript Easy
- Check for a power of two in JavaScript Medium
- Count the 1-bits of a number in JavaScript Medium
- Merge user settings with defaults using ?? in JavaScript Medium
- Reverse the digits of a number in JavaScript Easy
- Largest of three numbers with the ternary operator in JavaScript Easy
- Operator precedence quiz evaluator in JavaScript Hard
Conditional Statements 10 questions
- Grade and division from marks in JavaScript Easy
- Triangle type from three sides in JavaScript Easy
- Roots of a quadratic equation in JavaScript Medium
- Day name and type from a number with switch in JavaScript Easy
- Income tax with slab rates in JavaScript Hard
- Classify characters with switch (true) in JavaScript Medium
- ATM transactions with validation in JavaScript Medium
- Rock, paper, scissors winner in JavaScript Medium
- FizzBuzz in JavaScript Easy
- Movie ticket price with several rules in JavaScript Medium
Loops 10 questions
- Sum and average of even and odd numbers in JavaScript Easy
- Prime numbers up to 50 in JavaScript Easy
- Star pyramid pattern in JavaScript Easy
- Three-digit Armstrong numbers in JavaScript Medium
- GCD and LCM with Euclid's algorithm in JavaScript Medium
- Palindrome numbers in a range in JavaScript Medium
- Floyd's triangle in JavaScript Easy
- First repeated value in JavaScript Medium
- Decimal to binary with a loop in JavaScript Medium
- Perfect numbers up to 10,000 in JavaScript Hard
Functions 10 questions
- Area calculator with default parameters in JavaScript Easy
- Average of any number of values in JavaScript Easy
- compose and pipe in JavaScript Hard
- A function that runs only once in JavaScript Medium
- Memoized Fibonacci in JavaScript Hard
- Recursive factorial and fast power in JavaScript Easy
- Discount calculator factory in JavaScript Medium
- Apply a list of price rules with callbacks in JavaScript Medium
- Count how often a function is called in JavaScript Medium
- Password validator with helper functions in JavaScript Medium
Scope and Hoisting 10 questions
- Bank account with private balance in JavaScript Medium
- Unique ID generator in JavaScript Easy
- Simple rate limiter in JavaScript Hard
- Configurable logger with levels in JavaScript Medium
- Stack with private storage in JavaScript Medium
- Shopping cart with private items in JavaScript Medium
- Running average with a closure in JavaScript Easy
- Cycle through options with a closure in JavaScript Easy
- Cache with expiry using a closure in JavaScript Hard
- Lazy initialisation in JavaScript Medium
Arrays 10 questions
- Second largest element in JavaScript Medium
- Remove duplicates from an array in JavaScript Easy
- Rotate an array by k positions in JavaScript Medium
- Merge two sorted arrays in JavaScript Medium
- Transpose a matrix in JavaScript Medium
- Split an array into chunks in JavaScript Easy
- Move all zeros to the end in JavaScript Medium
- Find the missing number from 1 to n in JavaScript Easy
- Frequency of elements and the most frequent one in JavaScript Medium
- Pairs with a given sum (two sum) in JavaScript Hard
Strings 10 questions
- Palindrome check ignoring case and punctuation in JavaScript Easy
- First non-repeating character in JavaScript Medium
- Convert a sentence to title case in JavaScript Easy
- Check whether two words are anagrams in JavaScript Medium
- Longest word in a sentence in JavaScript Easy
- Caesar cipher encrypt and decrypt in JavaScript Medium
- Compress repeated characters in JavaScript Medium
- Mask a card number and an email address in JavaScript Easy
- Count words and occurrences of a word in JavaScript Medium
- Longest substring without repeating characters in JavaScript Hard
Objects 10 questions
- Group an array of objects by a key in JavaScript Medium
- Deep clone an object recursively in JavaScript Hard
- Deep equality of two objects in JavaScript Hard
- Invert an object's keys and values in JavaScript Easy
- pick and omit properties in JavaScript Medium
- Read a nested value by path in JavaScript Medium
- Total inventory value with Object.entries in JavaScript Easy
- Flatten a nested object to dot keys in JavaScript Hard
- Constructor function with a prototype method in JavaScript Medium
- Find the changed fields between two objects in JavaScript Medium
Array Methods 10 questions
- Class results with filter, map and reduce in JavaScript Easy
- Remove duplicate objects by id in JavaScript Medium
- Flatten and sum nested arrays in JavaScript Easy
- Implement map, filter and reduce yourself in JavaScript Hard
- Count occurrences with reduce in JavaScript Easy
- Unique long words in a sentence in JavaScript Medium
- Zip two arrays into an object in JavaScript Easy
- Partition an array into two groups in JavaScript Medium
- Group words by their first letter in JavaScript Medium
- Validate form fields with every and some in JavaScript Medium
String Methods 10 questions
- Create a URL slug from a title in JavaScript Easy
- Convert text to sentence case in JavaScript Medium
- Count occurrences of a substring in JavaScript Medium
- Validate Indian mobile numbers and PAN in JavaScript Medium
- Extract hashtags and mentions in JavaScript Medium
- A tiny template engine in JavaScript Hard
- Convert between camelCase and snake_case in JavaScript Medium
- Truncate text at a word boundary in JavaScript Easy
- Parse a URL query string in JavaScript Medium
- Highlight a search term in text in JavaScript Hard
ES6 Features 10 questions
- Employee and manager classes in JavaScript Medium
- Stack class with private fields in JavaScript Medium
- LRU cache with a Map in JavaScript Hard
- A simple event emitter in JavaScript Hard
- An iterable Range class in JavaScript Medium
- Infinite Fibonacci generator in JavaScript Medium
- Union, intersection and difference with Sets in JavaScript Easy
- Word frequency with a Map in JavaScript Easy
- Savings account with inheritance and a static counter in JavaScript Medium
- An "abstract" base class in JavaScript Medium
Arrow Functions 10 questions
- Rewrite utility functions as arrow functions in JavaScript Easy
- Curried GST calculator in JavaScript Medium
- Event handlers with class-field arrows in JavaScript Hard
- A lap timer that keeps this in callbacks in JavaScript Medium
- Filter and sort products with arrow functions in JavaScript Easy
- once and after helpers with arrow functions in JavaScript Medium
- Partial application with arrow functions in JavaScript Medium
- Calculator with a table of arrow functions in JavaScript Easy
- A string transformation pipeline with arrows in JavaScript Medium
- Grouping and counting with arrow one-liners in JavaScript Easy
Destructuring 10 questions
- Read weather data from an API response in JavaScript Medium
- A function that returns several statistics in JavaScript Easy
- Format addresses with destructuring defaults in JavaScript Easy
- Convert tuples to objects in JavaScript Easy
- Merge user options with defaults using destructuring in JavaScript Medium
- Parse CSV rows with destructuring in JavaScript Medium
- Simulate React's useState with destructuring in JavaScript Hard
- Remove sensitive fields with object rest in JavaScript Medium
- Swap adjacent elements with destructuring in JavaScript Easy
- Read deep configuration safely in JavaScript Hard
Spread and Rest Operators 10 questions
- Merge arrays into a unique sorted list in JavaScript Easy
- A variadic message formatter in JavaScript Easy
- Merge nested settings with spread in JavaScript Medium
- Immutable list updates for a to-do app in JavaScript Medium
- Clone and enrich records with spread in JavaScript Easy
- Highest and lowest values in nested arrays in JavaScript Easy
- Zip any number of arrays in JavaScript Medium
- Build a search query with conditional spread in JavaScript Medium
- Toggle selections immutably in JavaScript Medium
- A generic curry function with rest parameters in JavaScript Hard
Closures 10 questions
- Debounce an autosave in JavaScript Hard
- Throttle a function with a clock in JavaScript Hard
- Memoize with cache statistics in JavaScript Medium
- Limit login attempts with a closure in JavaScript Medium
- Subscriptions that return an unsubscribe function in JavaScript Medium
- A resettable number sequence in JavaScript Easy
- A function spy that records calls in JavaScript Medium
- A quiz scorer with private answers in JavaScript Easy
- A stopwatch with laps using closures in JavaScript Medium
- Count events in the last N seconds with a closure in JavaScript Hard
Callbacks 10 questions
- Retry a failing task with callbacks in JavaScript Hard
- Run asynchronous tasks one after another in JavaScript Medium
- Run tasks in parallel and keep the results in order in JavaScript Hard
- Report download progress with callbacks in JavaScript Easy
- Validation with success and failure callbacks in JavaScript Easy
- Give a callback task a timeout in JavaScript Hard
- Convert a callback API to promises in JavaScript Medium
- Sort with custom comparator callbacks in JavaScript Easy
- A countdown with onTick and onDone callbacks in JavaScript Easy
- An async waterfall in JavaScript Medium
Promises 10 questions
- A sleep helper and timed steps in JavaScript Easy
- Retry a promise with exponential backoff in JavaScript Hard
- Add a timeout to any promise in JavaScript Medium
- Run promise tasks in sequence in JavaScript Medium
- Run promises with a concurrency limit in JavaScript Hard
- A success/failure report with Promise.allSettled in JavaScript Medium
- Download from the fastest working mirror with Promise.any in JavaScript Medium
- Implement Promise.all yourself in JavaScript Hard
- Cache promises to avoid duplicate requests in JavaScript Medium
- Load profile data in parallel with Promise.all in JavaScript Easy
Async/Await 10 questions
- Retry an async operation with await in JavaScript Medium
- Download files sequentially and in parallel with async/await in JavaScript Easy
- Give an awaited call a time limit in JavaScript Medium
- Process a queue with limited concurrency using async/await in JavaScript Hard
- Load all pages of an API with an async generator in JavaScript Hard
- Poll a job until it is ready with async/await in JavaScript Medium
- Cache async results with async/await in JavaScript Medium
- Send bulk notifications with await and allSettled in JavaScript Easy
- A typing effect with await in JavaScript Easy
- A class with a static async factory in JavaScript Hard
Event Loop 10 questions
- Simulate the event loop in JavaScript Hard
- Process a large array in chunks without blocking in JavaScript Medium
- Batch DOM-style updates with microtasks in JavaScript Medium
- Implement setTimeout with a virtual clock in JavaScript Hard
- Sleep sort with setTimeout in JavaScript Easy
- Build an interval with recursive setTimeout in JavaScript Medium
- A cooperative round-robin scheduler with generators in JavaScript Hard
- Record the execution order of async callbacks in JavaScript Medium
- Drain a message queue a few items per tick in JavaScript Medium
- Run tasks one per event-loop turn in JavaScript Medium
DOM Manipulation 10 questions
- Render an array as a list in JavaScript Easy
- A todo list with event delegation in JavaScript Medium
- A sortable table in JavaScript Hard
- Live search that filters a list in JavaScript Medium
- Validate a signup form in JavaScript Medium
- An accessible tabs component in JavaScript Medium
- A live character counter in JavaScript Easy
- Print the DOM tree recursively in JavaScript Medium
- Highlight a search term safely in JavaScript Hard
- Components that talk through custom events in JavaScript Hard
Error Handling 10 questions
- Map custom errors to HTTP responses in JavaScript Medium
- A safe JSON parser with a fallback in JavaScript Easy
- Throw and handle typed errors for input in JavaScript Medium
- Wrap errors and print the cause chain in JavaScript Medium
- A Result type instead of exceptions in JavaScript Hard
- Wrap functions so errors are logged and defaulted in JavaScript Medium
- A bank transfer that rolls back on error in JavaScript Hard
- Serialise errors (with causes) to JSON in JavaScript Medium
- Guarantee resource cleanup with finally in JavaScript Medium
- Process a batch and report every failure in JavaScript Medium
Ready to test your Programming?
Timed online tests with instant scores and explanations.