Open In App

JavaScript Programming Examples

Last Updated : 19 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

JavaScript is a popular compiled programming language in the world of web development, providing to both new and experienced developers. Now, practicing programming examples is useful for improving your logical and coding skills.

JavaScript programming examples, encompassing fundamental syntax like Objects, Functions, and Arrays, to advanced topics like OOPs and event handling. These examples are designed to enhance your JavaScript proficiency and reinforce your programming skills through practical tasks.

JavaScript Examples

JavaScript Examples

JavaScript Programming Examples Topics

JavaScript ES6 Examples

Here in this section, we have compiled the most important JavaScript ES6 programming examples. So, if you are new or an expert in JavaScript and looking for a practice set of JavaScript programming examples scroll down below.

1 How to check two numbers are approximately equal in JavaScript?
2 How to declare variables in different ways in JavaScript?
3 How to replace the names of multiple object keys with the values provided using JavaScript?
4 How to get the first non-null/undefined argument in JavaScript?
5 Shorthand Syntax for Object Property Value in ES6
6 Motivation to bring symbols in ES6
7 What are decorators and how are they used in JavaScript?
8 How to use Typescript with native ES6 Promises?
9 How to clone array in ES6?
10 Array Helper Methods in ES6
11 How to dynamically load JS inside JS?
 

JavaScript Objects Examples

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.

1 How to check if a value is object-like in JavaScript?
2 How to compare two objects to determine the first object contains equivalent property values to the second object in JavaScript?
3 How to check if the provided value is an object created by the Object constructor in JavaScript?
4 How to convert two-dimensional array into an object in JavaScript?
5 How to create an object from two arrays in JavaScript?
6 Get the index of an object by its property.
7 How to use array that include and check an object against a property of an object?
8 How to print object by id in an array of objects in JavaScript?
9 How to create dynamic values and objects in JavaScript?
10 How to add a property to a JavaScript object using a variable as the name?
11 How to implement a filter() for Objects in JavaScript?
12 How to get all the methods of an object using JavaScript?
13 How to convert an Object {} to an Array [] of key-value pairs in JavaScript?
14 How to iterate over a JavaScript object?
15 How to add an object to an array in JavaScript?
16 How to get the last item of JavaScript object?
17 How to remove Objects from Associative Array in JavaScript?
18 How to remove duplicates from an array of objects using JavaScript?
19 How to get a key in a JavaScript object by its value?
20 How to push an array into the object in JavaScript?
21 How to get a subset of a javascript object’s properties?
22 How to check a JavaScript Object is a DOM Object?
23 How to remove a property from JavaScript object?
24 Flatten JavaScript objects into a single-depth Object
25 Creating objects in JavaScript (4 Different Ways)
26 Convert URL parameters to a JavaScript Object

JavaScript Function Examples

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.

1 Functions in JavaScript
2 Difference between regular functions and arrow functions
3 How to iterate over a callback n times in JavaScript ?
4 How to negate a predicate function in JavaScript ?
5 How to make a word count in textarea using JavaScript ?
6 How to add an element horizontally in Html page using JavaScript?
7 How to add fade-out effect using pure JavaScript ?
8 How to add fade-in effect using pure JavaScript?
9 How to implement a function that enable another function after specified time using JavaScript ?
10 Ways to implement Object.values() in JavaScript
11 How to get the index of the function in an array of functions which executed the fastest in JavaScript?
12 How to find out the caller function in JavaScript?
13 When to use PreventDefault( ) vs Return false in JavaScript?
14 What is the difference between call and apply in JavaScript?
15 Using the function* Declaration in JavaScript
16 Create a Mobile Toggle Navigation Menu using HTML, CSS and JavaScript
17 How to change the value of a global variable inside of a function using JavaScript ?
18 How to wait for a promise to finish before returning the variable of a function?
19 How to override a JavaScript function ?
20 How to include a JavaScript file in another JavaScript file ?
21 How to get the javascript function parameter names/values dynamically?
22 How to declare the optional function parameters in JavaScript ?
23 How to check a function is defined in JavaScript ?
24 How to measure time taken by a function to execute using JavaScript?
25 Passing a function as a parameter in JavaScript
26 How to call function from it name stored in a string using JavaScript?
27 How to create a function that invokes each provided function with the arguments it receives using JavaScript ?
28 How to create a function that invokes function with partials appended to the arguments in JavaScript ?
29 How to remove the key-value pairs corresponding to the given keys from an object using JavaScript ?
30 How to create a function that invokes each provided function with the arguments it receives using JavaScript ?

JavaScript Recursion Examples

Follow down the below section you will get multiple JavaScript programming examples based on Recursion.

1 Count pairs up to N having sum equal to their XOR
2 Count substrings having frequency of a character exceeding that of another character in a string
3 Sort the array using slow sort
4 Subtract 1 from a number represented as Linked List
5 Maximize sum of odd-indexed array elements by repeatedly selecting at most 2*M array elements from the beginning
6 Count ways to represent a number as sum of perfect squares
7 Number of M-length sorted arrays that can be formed using first N natural numbers
8 Program to insert an element at the Bottom of a Stack
9 Generate an array representing GCD of nodes of each vertical level of a Binary Tree
10 Minimum number of cameras required to monitor all nodes of a Binary Tree
11 Maximum number of plates that can be placed from top to bottom in increasing order of size
12 Median of all nodes from a given range in a Binary Search Tree ( BST )
13 Largest element in an N-ary Tree
14 Lowest Common Ancestor of the deepest leaves of a Binary Tree
15 Sum of subsets nearest to K possible from two given arrays
16 Minimum cost of purchasing at least X chocolates
17 Maximize cost of forming a set of words using given set of characters
18 Maximum product of a pair of nodes from largest connected component in a Graph
19 Count paths in a Binary Tree consisting of nodes in non-decreasing order
20 Tower of Hanoi
21 Length of longest subset consisting of A 0s and B 1s from an array of strings
22 Check if a path exists from a given cell to any boundary element of the Matrix with sum of elements not exceeding K
23 Modify Binary Tree by replacing each node with the sum of its Preorder Predecessor and Successor
24 Maximum score possible by removing substrings made up of single distinct character
25 Count all unique outcomes possible by performing S flips on N coins
26 Length of the longest path ending at vertex V in a Graph
27 Generate all possible combinations of K numbers that sums to N
28 Minimize difference between sum of two K-length subsets

JavaScript Number Examples

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.

1 How to add float numbers using JavaScript ?
2 Currency Converter in JavaScript
3 How to get median of an array of numbers in JavaScript ?
4 Round off a number to the next multiple of 5 using JavaScript
5 Convert a negative number to positive in JavaScript
6 Find quotient and remainder by dividing an integer in JavaScript
7 How to flatten a given array up to the specified depth in JavaScript ?
8 How to get the standard deviation of an array of numbers using JavaScript ?
9 How to evaluate binomial coefficient of two integers n and k in JavaScript ?
10 How to calculate greatest common divisor of two or more numbers/arrays in JavaScript ?
11 How to test a value x against predicate function and returns fn(x) or x in JavaScript ?
12 How to check two numbers are approximately equal in JavaScript ?
13 How to create slider to map a range of values in JavaScript ?
14 RMS Value Of Array in JavaScript

JavaScript Array Examples

If you are looking for a practice set of Array programs, then in this section we have mentioned multiple Array-based JavaScript programming examples.

1 How to get removed elements of a given array until the passed function returns true in JavaScript ?
2 How to filter values from an array for which the comparator function does not return true in JavaScript ?
3 How many numbers in the given array are less/equal to the given value using the percentile formula ?
4 How to remove specific elements from the left of a given array of elements using JavaScript ?
5 How to convert a 2D array to a comma-separated values (CSV) string in JavaScript ?
6 How to count number of occurrences of repeated names in an array of objects in JavaScript ?
7 How to count number of data types in an array in JavaScript ?
8 How to remove falsy values from an array in JavaScript ?
9 How to move specified number of elements to the end of an array in JavaScript ?
10 How to flatten a given array up to the specified depth in JavaScript ?
11 How to get the standard deviation of an array of numbers using JavaScript ?
12 How to get symmetric difference between two arrays in JavaScript ?
13 How to get n largest elements from array in JavaScript ?
14 How to find every element that exists in any of two given arrays once using JavaScript ?
15 How to find all elements in a given array except for the first one using JavaScript ?
16 How to remove n elements from the end of a given array in JavaScript ?
17 How to create an object from two arrays in JavaScript?
18 How to create a string by joining the elements of an array in JavaScript ?
19 How to splice an array without mutating the original Array?
20 Swapping two array elements in a single line using JavaScript
21 How to create HTML list from JavaScript array ?
22 How to get the same value from another array and assign to object of arrays?
23 How to truncate an array in JavaScript ?
24 How to print object by id in an array of objects in JavaScript?
25 How to convert a number into array in JavaScript ?
26 How to print unique elements from two unsorted arrays using JavaScript ?
27 How to transform a JavaScript iterator into an array?
28 How to add elements to an existing array dynamically in JavaScript ?
29 How to replace an item from an array in JavaScript?

JavaScript DateTime Examples

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.

1 How to calculate days left until next Christmas using JavaScript ?
2 How to get tomorrow’s date in a string format in JavaScript ?
3 How to convert UTC date time into local date time using JavaScript ?
4 How to check for two timestamp for the same day?
5 How to get seconds since epoch in JavaScript?
6 How to compare date part only without comparing time in JavaScript?
7 How to check the input date is equal to today’s date or not using JavaScript ?
8 Get the relative timestamp difference between dates in JavaScript
9 How to check if one date is between two dates in JavaScript ?
10 How to check if the given date is weekend ?
11 How to format current date in MM/DD/YYYY HH:MM:SS format using JavaScript ?
12 How to convert date to another timezone in JavaScript ?
13 How to check if date is less than 1 hour ago using JavaScript ?
14 How to check a date is valid or not using JavaScript ?
15 How to get the day and month of a year using JavaScript ?
16 How to store all dates in an array present in between given two dates in JavaScript ?
17 How to convert seconds to time string format hh:mm:ss using JavaScript ?
18 How do you display JavaScript datetime in 12 hour AM/PM format?
19 Converting milliseconds to date.
20 How to calculate the date three months prior using JavaScript ?
21 How to calculate minutes between two dates in JavaScript ?
22 How to calculate the yesterday’s date in JavaScript ?
23 How to get the first day of the year in JavaScript ?
24 How to get the first and last date of current month using JavaScript ?
25 How to remove time from date using JavaScript ?
26 How to get the current date in JavaScript ?
27 How to get the current date and time in seconds?

JavaScript String/Text Examples

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.

1 How to convert a string into a integer without using parseInt() function in JavaScript ?
2 How to generate all combinations of a string in JavaScript ?
3 How to replace line breaks with <br> using JavaScript ?
4 How to split multiline string into an array of lines in JavaScript ?
5 How to convert image into base64 string using JavaScript ?
6 How to check whether a passed string is palindrome or not in JavaScript ?
7 How to get the number of occurrences of each letter in specified string in JavaScript ?
8 How to find the longest word within the string in JavaScript ?
9 How to find unique characters of a string in JavaScript ?
10 How to create an element from a string in JavaScript?
11 How to get the first three characters of a string using JavaScript ?
12 How to check a given string is an anagram of another string in JavaScript ?
13 How to create half of the string in uppercase and the other half in lowercase?
14 Convert a number to a string in JavaScript
15 How to get a number of vowels in a string in JavaScript?
16 Difference between single-quoted and double-quoted strings in JavaScript
17 Convert user input string into regular expression using JavaScript
18 How to add method to String class in JavaScript?
19 How to convert long number into abbreviated string in JavaScript ?
20 How to get the longest string in an array using JavaScript ?
21 How to remove all Non-ASCII characters from the string using JavaScript ?
22 How to change the Content of a <textarea> using JavaScript ?
23 How to globally replace a forward slash in a JavaScript string ?
24 How to insert a string at a specific index in JavaScript ?
25 How to create hash from string in JavaScript ?
26 How to pad a string to get the determined length using JavaScript ?
27 How to get nth occurrence of a string in JavaScript ?
28 How to remove a character from string in JavaScript ?
29 How to convert string into float in JavaScript?
30 How to convert string to camel case in JavaScript ?

JavaScript Regular Expression Examples

Below we have listed down Regular Expression JavaScript programming examples. Practice these questions and know the use of break, clone, and more.

1 How to replace line breaks with <br> using JavaScript ?
2 How to clone a given regular expression in JavaScript ?
3 How to convert a string into kebab case using JavaScript ?
4 How to validate URL using regular expression in JavaScript?

JavaScript DOM Examples

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.

1 How to store data in the DOM ?
2 How to specify the URL that will process the data supplied through input(s) when the form is submitted?
3 How to store data to DOM ?
4 How to get elements of specific class inside a div ?
5 How to check the given element has the specified class in JavaScript ?
6 How getElementByID works in JavaScript ?
7 What is shadow root and how to use it ?
8 What is the use of the “no-js” class in HTML ?
9 How to Combine multiple elements and append the result into a div using JavaScript ?
10 How to get the information from a meta tag using JavaScript?
11 How to check if an element is visible in DOM ?
12 How to check a JavaScript Object is a DOM Object ?
13 How to remove an HTML element using JavaScript ?
14 Replace a DOM element with another DOM element in place
15 Set the focus to HTML form element using JavaScript

JavaScript JSON Examples

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.

1 How to read information from nested objects in DataTables ?
2 How to Convert CSV to JSON file and vice-versa in JavaScript ?
3 Working with APIs in JavaScript
4 Difference Between JSON and BSON
5 Difference Between JSON and AJAX
6 How to convert JSON results into a date using JavaScript ?
7 How to swap key and value of JSON element using JavaScript ?
8 How to send a JSON object to a server using Javascript?
9 How to Convert JS Object to JSON String in JQuery/Javascript?
10 How to convert JSON data to a html table using JavaScript/jQuery ?
11 Deserializing a JSON into a JavaScript object
12 How to pretty print JSON string in JavaScript ?
13 Check if a key exists inside a JSON object
14 How to add an element to a JSON object?
15 Remove a JSON attribute
16 Interesting facts about JSON
17 Difference between JSON and XML
18 Converting JSON text to JavaScript Object
19 JSON | modify an array value of a JSON object

JavaScript Mini Projects

Once you have tried all the above JavaScript programming examples, then explore this section to find out the mini JavaScript examples. Ihese examples help you to upskale you logical skills.

1 Design a Text Editor using Javascript
2 Generate a Random Birthday Wishes using JavaScript
3 Design a Digital Clock using JavaScript
4 Design a Todo List using JavaScript
5 Create a Mobile Toggle Navigation Menu using JavaScript
6 Simple Tic-Tac-Toe Game using JavaScript
7 Design a Simple Calculator using JavaScript
8 Design a Scientific Calculator using JavaScript
9 Create an Image Lightbox Gallery using JavaScript
10 Preview Image on click in Gallery View using JavaScript
11 Add filter with Portfolio Gallery using JavaScript
12 Create a Mobile Toggle Navigation Menu using JavaScript
13 Create a Hoverable Side Navigation using JavaScript


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads