JavaScript fundamental (ES6) - Exercises, Practice, Solution
JavaScript fundamental [118 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts.]151. Write a JavaScript program to run a function in a separate thread by using a Web Worker, allowing long running functions to not block the UI. Go to the editor
152. Write a JavaScript program to round a number to a specified amount of digits. Go to the editor
153. Write a JavaScript program to reverse the order of the characters in the string. Go to the editor
154. Write a JavaScript program to create an object composed of the properties the given function returns falsey for. The function is invoked with two arguments: (value, key).Go to the editor
155. Write a JavaScript program that takes a predicate and array, like Array.filter(), but only keeps x if pred(x) returns false. Go to the editor
156. Write a JavaScript program to apply a function against an accumulator and each element in the array (from left to right), returning an array of successively reduced values. Go to the editor
157. Write a JavaScript program to redirect to a specified URL. Go to the editor
158. Write a JavaScript program to create a function that invokes the provided function with its arguments arranged according to the specified indexes. Go to the editor
159. Write a JavaScript program to get an array of lines from the specified file.Go to the editor
160. Write a JavaScript program to mutate the original array to filter out the values specified, based on a given iterator function. Go to the editor
161. Write a JavaScript program to mutate the original array to filter out the values specified. Returns the removed elements.Go to the editor
162. Write a JavaScript program to convert an asynchronous function to return a promise. Go to the editor
163. Write a JavaScript program to convert a number in bytes to a human-readable string. Go to the editor
164. Write a JavaScript program that will return the singular or plural form of the word based on the input number.Go to the editor
165. Write a JavaScript program to perform left-to-right function composition. Go to the editor
166. Write a JavaScript program to perform left-to-right function composition for asynchronous functions. Go to the editor
167. Write a JavaScript program to calculate how many numbers in the given array are less or equal to the given value using the percentile formula. Go to the editor
168. Write a JavaScript program to group the elements into two arrays, depending on the provided function's truthiness for each element. Go to the editor
169. Write a JavaScript program to create a function that invokes fn with partials appended to the arguments it receives. Go to the editor
170. Write a JavaScript program to create a function that invokes fn with partials prepended to the arguments it receives. Go to the editor
171. Write a JavaScript program to parse an HTTP Cookie header string and return an object of all cookie name-value pairs. Go to the editor
172. Write a JavaScript program to create a function that invokes the provided function with its arguments transformed. Go to the editor
173. Write a JavaScript program to get the nth element of an given array. Go to the editor
174. Write a JavaScript program to convert a NodeList to an array. Go to the editor
175. Write a JavaScript program to get the index of the function in an array of functions which executed the fastest. Go to the editor
176. Write a JavaScript program to get the n minimum elements from the provided array. If n is greater than or equal to the provided array's length, then return the original array(sorted in ascending order). Go to the editor
177. Write a JavaScript program to get the minimum value of an array, after mapping each element to a value using the provided function. Go to the editor
178. Write a JavaScript program to create a new object from the combination of two or more objects. Go to the editor
179. Write a JavaScript program to compare two objects to determine if the first one contains equivalent property values to the second one, based on a provided function. Go to the editor
180. Write a JavaScript program to create a new object from the specified object, where all the keys are in lowercase. Go to the editor
181. Write a JavaScript program to get the last element from an given array. Go to the editor
182. Write a JavaScript program to join all elements of an array into a string and returns this string. Uses a separator and an end separator. Go to the editor
183. Write a JavaScript program to check if the provided argument is a valid JSON. Go to the editor
184. Write a JavaScript program to check if a given string is upper case or not. Go to the editor
185. Write a JavaScript program that will return true if the specified value is undefined, false otherwise. Go to the editor
186. Write a JavaScript program to check if the given argument is a symbol. Go to the editor
187. Write a JavaScript program to check if the given argument is a string. Go to the editor
188. Write a JavaScript program that will return 1 if the array is sorted in ascending order, -1 if it is sorted in descending order or 0 if it is not sorted.Go to the editor
189. Write a JavaScript program that will return true if an object looks like a Promise, false otherwise. Go to the editor
190. Write a JavaScript program to get a boolean determining if the passed value is primitive or not. Go to the editor
191. Write a JavaScript program to check if the provided integer is a prime number is not. Go to the editor
192. Write a JavaScript program to check if the provided value is an object created by the Object constructor. Go to the editor
193. Write a JavaScript program to check if a value is object-like. Check if the provided value is not null and its typeof is equal to 'object'.Go to the editor
194. Write a JavaScript program to get a boolean determining if the passed value is an object or not. Go to the editor
195. Write a JavaScript program to check if a given argument is a number. Go to the editor
196. Write a JavaScript program that will return true if the specified value is null, false otherwise. Go to the editor
197. Write a JavaScript program to check if a string is lower case or not. Go to the editor
198. Write a JavaScript program to check if the given argument is a function. Go to the editor
199. Write a JavaScript program that will return true if the given number is even, false otherwise. Go to the editor
200. Write a JavaScript program that will return true if a value is an empty object, collection, map or set, has no enumerable properties or is any type that is not considered a collection. Go to the editor
201. Write a JavaScript program to check if the first numeric argument is divisible by the second one. Go to the editor
202. Write a JavaScript program to check if a given number is even or not. Go to the editor
203. Write a JavaScript program to determine if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors. Go to the editor
204. Write a JavaScript program that will check if the given argument is a native boolean element. Go to the editor
205. Write a JavaScript program to check if the provided argument is array-like (i.e. is iterable). Go to the editor
206. Write a JavaScript program to check if a given string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters). Go to the editor
207. Write a JavaScript program to that will return true if the given string is an absolute URL, false otherwise. Go to the editor
208. Write a JavaScript program to check if the provided value is of the specified type. Go to the editor
209. Write a JavaScript program to get a list of elements that exist in both arrays, using a provided comparator function. Go to the editor
210. Write a JavaScript program to get a list of elements that exist in both arrays, after applying the provided function to each array element of both. Go to the editor
211. Write a JavaScript program to get a list of elements that exist in both arrays. Go to the editor
212. Write a JavaScript program to create a n-dimensional array with given value. Go to the editor
213. Write a JavaScript program to initialize and fill an array with the specified values. Go to the editor
214. Write a JavaScript program to Initializes an array containing the numbers in the specified range (in reverse) where start and end are inclusive with their common difference step. Go to the editor
215. Write a JavaScript program to get all the elements of an array except the last one. Go to the editor
216. Write a JavaScript program to get all indices of val in an array. If val never occurs, returns []. Go to the editor
217. Write a JavaScript program to check if the given number falls within the given range. Go to the editor
218. Write a JavaScript program to get the number of times a function executed per second. hz is the unit for hertz, the unit of frequency defined as one cycle per second. Go to the editor
219. Write a JavaScript program to calculate the Hamming distance between two values. Go to the editor
220. Write a JavaScript program to get the native type of a value. Returns lowercased constructor name of value, "undefined" or "null" if value is undefined or null. Go to the editor
221. Write a JavaScript program to get a string of the form HH:MM:SS from a Date object. Go to the editor
222. Write a JavaScript program that initializes an array containing the numbers in the specified range where start and end are inclusive and the ratio between two terms is step. Returns an error if step equals 1. Go to the editor
223. Write a JavaScript program to calculate the greatest common divisor between two or more numbers/arrays. Go to the editor
224. Write a JavaScript program to remove HTML/XML tags from string. Go to the editor
225. Write a JavaScript program to get the standard deviation of an array of numbers. Go to the editor
226. Write a JavaScript program to get n random elements at unique keys from array up to the size of array. Go to the editor
227. Write a JavaScript program to remove elements from an array for which the given function returns false. Go to the editor
228. Write a JavaScript program to log the name of a function. Go to the editor
229. Write a JavaScript program to convert a string from camelcase. Go to the editor
230. Write a JavaScript program to get the human readable format of the given number of milliseconds. Go to the editor
231. Write a JavaScript program to iterate over all own properties of an object in reverse, running a callback for each one. Go to the editor
232. Write a JavaScript program that takes a function as an argument, then makes the first argument the last. Go to the editor
233. Write a JavaScript program to flatten an object with the paths for keys. Go to the editor
234. Write a JavaScript program to flatten a given array up to the specified depth. Go to the editor
235. Write a JavaScript program to get the last key that satisfies the provided testing function, otherwise undefined is returned. Go to the editor
236. Write a JavaScript program to get the first key that satisfies the provided testing function. Otherwise return undefined. Go to the editor
237. Write a JavaScript program to generate an array, containing the Fibonacci sequence, up until the nth term. Go to the editor
238. Write a JavaScript program to calculate the factorial of a number. Go to the editor
239. Write a JavaScript program to escape a string to use in a regular expression. Go to the editor
240. Write a JavaScript program that will return true if the parent element contains the child element, false otherwise. Go to the editor
241. Write a JavaScript program to remove elements in an array until the passed function returns true. Returns the remaining elements in the array. Go to the editor
242. Write a JavaScript program to remove elements from the end of an array until the passed function returns true. Returns the remaining elements in the array. Go to the editor
243. Write a JavaScript program to get the distance between two given points. Go to the editor
244. Write a JavaScript program to get the difference between two given arrays. Go to the editor
245. Write a JavaScript program to Invokes the provided function after wait milliseconds. Go to the editor
246. Write a JavaScript program to convert an given angle from degrees to radians. Go to the editor
247. Write a JavaScript program that Assigns default values for all properties in an object that are undefined. Go to the editor
248. Write a JavaScript program to deep flatten an array. Go to the editor
249. Write a JavaScript program to get the current URL. Go to the editor
250. Write a JavaScript program to create an element from a string (without appending it to the document). Go to the editor
251. Write a JavaScript program to write a JSON object to a file. Go to the editor
252. Write a JavaScript program to convert the values of RGB components to a color code. Go to the editor
253. Write a JavaScript program to generate a UUID in a browser. Go to the editor
254. Write a JavaScript program to generate a UUID in Node.JS. Use crypto API to generate a UUID, compliant with RFC4122 version 4. Go to the editor
255. Write a JavaScript program that will return true if the provided predicate function returns true for at least one element in a collection, false otherwise. Go to the editor
256. Write a JavaScript program to check if two given numbers are approximately equal to each other. Go to the editor
257. Write a JavaScript program to convert a 2D array to a comma-separated values (CSV) string. Go to the editor
258. Write a JavaScript program to create a function that accepts up to n arguments, ignoring any additional arguments. Go to the editor
259. Write a JavaScript program to decode a string of data which has been encoded using base-64 encoding. Go to the editor
260. Write a JavaScript program to evaluate the binomial coefficient of two integers n and k. Go to the editor
261. Write a JavaScript program that will return true if the bottom of the page is visible, false otherwise. Go to the editor
262. Write a JavaScript program to create a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data. Go to the editor
263. Write a JavaScript program to capitalize the first letter of a string. Go to the editor
264. Write a JavaScript program to capitalize the first letter of every word in a string. Go to the editor
265. Write a JavaScript program to chunk an array into smaller arrays of a specified size. Go to the editor
266. Write a JavaScript program to clamp a number within the inclusive range specified by the given boundary values a and b. Go to the editor
267. Write a JavaScript program to calculate the midpoint between two pairs of points. Go to the editor
268. Write a JavaScript program to find the index of an array item in a for loop. Go to the editor
More to Come !
* To run the code mouse over on Result panel and click on 'RERUN' button.*
Live Demo:
See the Pen javascript-common-editor by w3resource (@w3resource) on CodePen.
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
JavaScript: Tips of the Day
Creates an object composed of the properties the given function returns truthy for. The function is invoked with two arguments: (value, key)
Example:
const tips_composed = (obj, fn) => Object.keys(obj) .filter(k => fn(obj[k], k)) .reduce((acc, key) => ((acc[key] = obj[key]), acc), {}); console.log(tips_composed({ p: 2, q: '4', r: 6 }, x => typeof x === 'number'));
Output:
[object Object] { p: 2, r: 6 }
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises