JavaScript Programming Examples
JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.
- Used both on the client-side and server-side, making it versatile for full-stack development.
- Supports a wide range of frameworks and libraries like React, Angular, and Node.js.
- Plays a key role in creating modern, responsive, and interactive web applications.
ES6
This section features essential ES6 JavaScript programming examples. Whether you’re just starting or have mastered JavaScript, these examples provide a solid foundation for mastering modern JavaScript features.
- Check for Approximately Equal
- Declare variables in different ways
- Replacing multiple object Keys
- First non-null/undefined argument
- Shorthand for Object Property V
- Motivation to bring symbols in ES6
- Decorators and how are they used
- Use Typescript with native ES6 Promises
- Clone array in ES6
- Array Helper Methods in ES6
- Dynamically load JS inside JS
Objects
In this section, we've collected important JavaScript examples that deal with objects. Whether you're just starting or you're already familiar with JavaScript and want to practice, take a look at the examples below.
- Check if a value is object-like
- Compare object by property value
- Check for plan Object
- Create an object from two arrays
- Get the index of an object by its property
- Check object in array property
- Print object by id in an array of objects
- Add dynamic property to object
- Implement a filter() for Objects
- All the methods of an object
- Convert an Object to JS Array
- Iterate over a JavaScript object
- Remove Objects from Associative Array
- Subset of a javascript object’s properties
- Check a JavaScript Object is a DOM Object
- Remove a property from JavaScript object
- Remove Objects from Associative Array
- Flatten JavaScript objects into a single-depth Object
- Creating objects
- Convert URL Parameters to Object
Function
Within this section, we've compiled important JavaScript Functions-based programming examples. So if you are seeking JavaScript function-based practice question the deep down below.
- Functions in JavaScript
- Regular functions Vs Arrow
- Iterate over a callback n times
- Negate a predicate function
- Make a word count in textarea
- Add element horizontally in Html page
- Add fade-out effect using pure
- Delay Function Execution
- Find out the caller function
- PreventDefault( ) Vs Return false
- Call Vs apply
- Using the function* Declaration
- Mobile Toggle Navigation Menu
- Modify Global Variable in Function
- Promise Before Returning
- Override a JavaScript function
- Import JavaScript File
- Retrieve Function Parameters Dynamically
- Declare the optional function parameters
- Check a function is defined
- Measure time taken by a function to execute
- Passing a function as a parameter
- Call function from it name stored in a string
- Invoke Multiple Functions with Arguments
- Invoke Function with Partial Arguments
- Remove Keys from Object
- Invoke Functions with Received Arguments
Recursion
Follow down the below section you will get multiple JavaScript programming examples based on Recursion.
- Pairs where sum equals XOR
- Count substrings by character frequency
- Sort the array using slow sort
- Subtract 1 from a Linked List
- Maximize odd-indexed array sum with 2M picks
- Count ways to sum as perfect squares
- Number of M-length sorted arrays from N
- Insert element at bottom of stack
- GCD array of Binary Tree verticals
- Min cameras to monitor Binary Tree
- Max plates in increasing size order
- Median of nodes in BST range
- Largest element in an N-ary Tree
- LCA of deepest leaves in Binary Tree
- Closest subset sum to K from 2 arrays
- Min cost to buy at least X chocolates
- Maximize word set cost using characters
- Max product from largest Graph component
- Count non-decreasing paths in Binary Tree
- Tower of Hanoi
- Longest subset of A 0s & B 1s
- Path to boundary with sum ≤ K in matrix
- Modify Binary Tree using Preorder sum
- Max score by removing single-char substrings
- Count outcomes from S coin flips
- Longest path ending at vertex V in Graph
- Generate all K-number combinations summing to N
- Minimize difference between sum of two K-length subsets
Number
Explore the list of number-based JavaScript programming examples. Here you will get examples of how to add float numbers, how to make a currency converter, and more number-based examples.
- Add float numbers
- Currency Converter in JavaScript
- Median of an array of numbers
- Round off a number to the next multiple of 5
- Convert a negative number to positive
- Quotient and remainder by dividing an integer
- Flatten a given array up to the specified depth
- Standard deviation of an array of numbers
- Evaluate binomial coefficient of two integers n and k
- GCD of Array
- Test a value x against predicate function and returns fn(x) or x
- Check two numbers are approximately equal
- Create slider to map a range of values
- RMS Value Of Array in JavaScript
Array
If you are looking for a practice set of Array programs, then in this section we have mentioned multiple Array-based JavaScript programming examples.
- Remove array elements until condition is met
- Filter array values by comparator
- Percentile-based number filter
- Remove elements from array start
- Convert 2D array to CSV
- Count duplicate names in objects array
- Count number of data types in an array
- Move elements to array end
- Flatten a given array up to the specified depth
- Standard deviation of numbers
- Symmetric difference between two arrays
- Get n largest elements from array
- Find unique elements from two arrays
- Get all elements except first
- Remove elements from array end
- Create an object from two arrays
- Convert array to string
- Splice an array without mutating the original
- Swapping two array elements in a single line
- Create HTML list
- Assign array values to object
- Truncate an array
- Print object by id in an array of objects
- Convert a number into array
- Print unique elements from two unsorted arrays
- Transform a JavaScript iterator into an array
- Add elements in existing array dynamically
- Replace item from array
DateTime
Here in the section, we've compiled the most important DateTime JavaScript programming examples. These examples are designed to deepen your understanding of working with date and time in JavaScript.
- Days until next Christmas
- Get tomorrow’s date string
- Convert UTC to local date
- Check if two timestamps are same day
- Get seconds since epoch
- Compare dates ignoring time
- Check if input date is today
- Check if date is weekend
- Format date as MM/DD/YYYY HH:MM:SS
- Convert date to another timezone
- Check if date < 1 hour ago
- Validate a date
- Day and month of year
- Store all dates between two dates
- Convert seconds to hh:mm:ss format
- Display date in 12-hour AM/PM format
- Converting milliseconds to date.
- Date three months prior
- Calculate minutes between two dates
- Yesterday’s date
- First day of the year
- First and last date of current month
- Remove time from date
- Current date
- Current date/time in seconds
String
Explore the practice set of String/Text JavaScript examples. All the examples listed below will help you master the art of handling text data efficiently in your JavaScript projects.
- String to integer without parseInt
- Generate all string combinations
- Replace line breaks with <br>
- Split multiline string into array
- Convert image to base64 string
- Check if string is palindrome
- Count letter occurrences in string
- Find longest word in string
- Unique characters of string
- Create element from string
- First three characters
- Check if string is anagram
- Half uppercase, half lowercase string
- Convert number to string
- Count vowels in string
- Single vs double quotes in string
- Convert string to RegExp
- Add method to String class
- Abbreviate long number string
- Find longest string in array
- Remove non-ASCII characters
- Change <textarea> content
- Globally replace forward slash
- Insert string at specific index
- Create hash from string
- Remove character from string
- Convert string to float
- Convert string to camel case
Regular Expression
Below we have listed down Regular Expression JavaScript programming examples. Practice these questions and know the use of break, clone, and more.
- Replace line breaks with <br>
- Clone a given regular expression
- Convert a string into kebab case
- Validate URL using regular expression
DOM
In this DOM dedicated section, we have listed 15 DOM-based JavaScript examples JavaScript. Explore these examples and get to know how to save data in DOM, how to specify class in div, and more.
- Store data in the DOM
- Set form action URL
- Store data to DOM
- Elements by class in div
- Check if element has class
- How getElementByID works
- Shadow root usage
- Purpose of “no-js” class
- Combine and append elements to div
- Meta tag info
- Check if element is visible
- Check if object is DOM element
- Remove HTML element
- Replace DOM element
- Set focus to form element
JSON
Under JSON Examples, we've compiled JavaScript JSON-based programming examples. So if you are looking to refine your skills, dive into the examples listed below for practical learning.
- Read nested objects in DataTables
- Convert CSV to JSON and vice versa
- Work with APIs in JS
- JSON vs BSON
- JSON vs AJAX
- Convert JSON date in JS
- Swap key and value in JSON
- Send JSON to server
- Convert JS object to JSON string
- JSON to HTML table
- Deserialize JSON to JS object
- Pretty print JSON
- Check key in JSON object
- Add element to JSON object
- Remove a JSON attribute
- Interesting facts about JSON
- Difference between JSON and XMLJSON vs XML
- Convert JSON text to JS object
- Modify array value in JSON object
Mini Projects
Once you have tried all the above JavaScript programming examples, then explore this section to find out the mini JavaScript examples. These examples help you to upskale you logical skills.
- Design a Text Editor using JavaScript
- Generate a Random Birthday Wishes using JavaScript
- Design a Digital Clock using JavaScript
- Design a Todo List using JavaScript
- Create a Mobile Toggle Navigation Menu using JavaScript
- Simple Tic-Tac-Toe Game using JavaScript
- Design a Simple Calculator using JavaScript
- Design a Scientific Calculator using JavaScript
- Create an Image Lightbox Gallery using JavaScript
- Preview Image on click in Gallery View using JavaScript
- Add filter with Portfolio Gallery using JavaScript
- Create a Mobile Toggle Navigation Menu using JavaScript
- Create a Hoverable Side Navigation using JavaScript