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. Go to the editor]
151. Write a JavaScript program to run a function in a separate thread using a Web Worker. This allows long running functions to not block the UI.
152. Write a JavaScript program to round a number to a specified amount of digits.
153. Write a JavaScript program to reverse the order of characters in the string.
154. Write a JavaScript program to create an object composed of the properties the given function returns false for. The function is invoked with two arguments: (value and key).
155. Write a JavaScript program that takes a predicate and an array, like Array.filter(), but only keeps x if pred(x) returns false.
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.
157. Write a JavaScript program to redirect to a specified URL.
158. Write a JavaScript program to create a function that invokes the provided function with its arguments arranged according to the specified indexes.
159. Write a JavaScript program to get an array of lines from the specified file.
160. Write a JavaScript program to mutate the original array to filter out the values specified, based on a given iterator function.
161. Write a JavaScript program to mutate the original array to filter out the values specified. Returns the removed elements.
162. Write a JavaScript program to convert an asynchronous function to return a promise.
163. Write a JavaScript program to convert a number in bytes to a human-readable string.
164. Write a JavaScript program that returns the singular or plural form of the word based on the input number.
165. Write a JavaScript program to perform left-to-right function composition.
166. Write a JavaScript program to perform left-to-right function composition for asynchronous functions.
167. Write a JavaScript program to calculate how many numbers in the given array are less than or equal to the given value. This is done using the percentile formula.
168. Write a JavaScript program to group the elements into two arrays, depending on the provided function's truthiness for each element.
169. Write a JavaScript program to create a function that invokes fn with partials appended to the arguments it receives.
170. Write a JavaScript program to create a function that invokes fn with partials prepended to the arguments it receives.
171. Write a JavaScript program to parse an HTTP Cookie header string and return an object of all cookie name-value pairs.
172. Write a JavaScript program to create a function that invokes the provided function with its arguments transformed.
173. Write a JavaScript program to get the nth element of a given array of elements.
174. Write a JavaScript program to convert a NodeList into an array.
175. Write a JavaScript program to get the index of the function in an array of functions which executed the fastest.
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, return the original array (sorted in ascending order).
177. Write a JavaScript program to get the minimum value of an array, after mapping each element to a value using the provided function.
178. Write a JavaScript program to create a new object from the combination of two or more objects.
179. Write a JavaScript program to compare two objects to determine if the first contains equivalent property values to the second one. This is based on a provided function.
180. Write a JavaScript program to create an object from the specified object, where all keys are in lowercase.
181. Write a JavaScript program to get the last element from an given array.
182. Write a JavaScript program to join all elements of an array into a string and return this string. Use a separator and an end separator.
183. Write a JavaScript program to check if the provided argument is valid JSON.
184. Write a JavaScript program to check if a given string is upper case or not.
185. Write a JavaScript program that returns true if the specified value is undefined, false otherwise.
186. Write a JavaScript program to check if the given argument is a symbol.
187. Write a JavaScript program to check if the given argument is a string.
188. Write a JavaScript program that returns 1 if the array is sorted in ascending order. It returns -1 if it is sorted in descending order or 0 if it is not sorted.
189. Write a JavaScript program that returns true if an object looks like a Promise, false otherwise.
190. Write a JavaScript program to return a boolean determining if the passed value is primitive or not.
191. Write a JavaScript program to check if the provided integer is a prime number or is not.
192. Write a JavaScript program to check if the provided value is an object created by the Object constructor.
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'.
194. Write a JavaScript program to get a boolean determining if the passed value is an object or not.
195. Write a JavaScript program to check if a given argument is a number.
196. Write a JavaScript program that will return true if the specified value is null, false otherwise.
197. Write a JavaScript program to check if a string is lower case or not.
198. Write a JavaScript program to check if the given argument is a function.
199. Write a JavaScript program that returns true if the given number is even, false otherwise.
200. Write a JavaScript program that returns true if a value is an empty object, collection, map or set. It has no enumerable properties or is of any type not considered a collection.
201. Write a JavaScript program to check if the first numerical argument is divisible by the second one.
202. Write a JavaScript program to check if a given number is even or not.
203. Write a JavaScript program to determine if the current runtime environment is a browser. This is so that front-end modules can run on the server (Node) without errors.
204. Write a JavaScript program that checks if the given argument is a native Boolean element.
205. Write a JavaScript program to check if the provided argument is an array (i.e. iterable).
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).
207. Write a JavaScript program that returns true if the given string is an absolute URL, false otherwise.
208. Write a JavaScript program to check if the provided value is of the specified type.
209. Write a JavaScript program to get a list of elements in both arrays, using a provided comparator function.
210. Write a JavaScript program to get a list of elements in both arrays, after applying the provided function to each array element of both.
211. Write a JavaScript program to get a list of elements that exist in both arrays.
212. Write a JavaScript program to create a n-dimensional array with a given value.
213. Write a JavaScript program to initialize and fill an array with the specified values.
214. Write a JavaScript program to initialize an array containing the numbers in the specified range (in reverse) where start and end are inclusive of their common difference step.
215. Write a JavaScript program to get all the elements of an array except the last one.
216. Write a JavaScript program to get all val indices in an array. If val never occurs, return [].
217. Write a JavaScript program to check if the given number falls within the given range.
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.
219. Write a JavaScript program to calculate the Hamming distance between two values.
220. Write a JavaScript program to get the native type of a value. Returns the lowercased constructor name of value, "undefined" or "null" if value is undefined or null.
221. Write a JavaScript program to get a string like HH:MM:SS from a Date object.
222. Write a JavaScript program that initializes an array containing the numbers in the specified range. This is where start and end are inclusive and the ratio between the two terms is step. Returns an error if step equals 1.
223. Write a JavaScript program to calculate the greatest common divisor between two or more numbers/arrays.
224. Write a JavaScript program to remove HTML/XML tags from strings.
225. Write a JavaScript program to get the standard deviation of an array of numbers.
226. Write a JavaScript program to get n random elements with unique keys from an array up to the size of the array.
227. Write a JavaScript program to remove elements from an array for which the given function returns false.
228. Write a JavaScript program to log the name of a function.
229. Write a JavaScript program to convert a string from camelcase.
230. Write a JavaScript program to generate the human-readable format in the given number of milliseconds.
231. Write a JavaScript program to iterate over all the properties of an object in reverse, running a callback for each one.
232. Write a JavaScript program that takes a function as an argument, then makes the first argument the last.
233. Write a JavaScript program to flatten an object with the paths for keys.
234. Write a JavaScript program to flatten a given array to the specified depth.
235. Write a JavaScript program to get the last key that satisfies the provided testing function, otherwise undefined is returned.
236. Write a JavaScript program to get the first key that satisfies the provided testing function. Otherwise return undefined.
237. Write a JavaScript program to generate an array containing the Fibonacci sequence, up to the nth term.
238. Write a JavaScript program to calculate the factorial of a number.
239. Write a JavaScript program to escape a string to use in a regular expression.
240. Write a JavaScript program that returns true if the parent element contains the child element, false otherwise.
241. Write a JavaScript program to remove elements from an array until the passed function returns true. Returns the remaining elements in the array.
242. Write a JavaScript program to remove elements from the end of an array until the passed function returns true. Returns the remaining elements of the array.
243. Write a JavaScript program to get the distance between two given points.
244. Write a JavaScript program to get the difference between two given arrays.
245. Write a JavaScript program that invokes the provided function after a few milliseconds.
246. Write a JavaScript program to convert angles from degrees to radians.
247. Write a JavaScript program that assigns default values to all undefined properties in an object.
248. Write a JavaScript program to deep flatten an array.
249. Write a JavaScript program to get the current URL.
250. Write a JavaScript program to create an element from a string (without appending it to the document).
251. Write a JavaScript program to write a JSON object to a file.
252. Write a JavaScript program to convert the values of RGB components to a color code.
253. Write a JavaScript program to generate a UUID in a browser.
254. Write a JavaScript program to generate a UUID in Node.JS. Use crypto API to generate a UUID, compliant with RFC4122 version 4.
255. Write a JavaScript program that returns true if the provided predicate function returns true for at least one element in a collection, false otherwise.
256. Write a JavaScript program to check if two given numbers are approximately equal to each other.
257. Write a JavaScript program to convert a 2D array to a comma-separated value (CSV) string.
258. Write a JavaScript program to create a function that accepts up to n arguments, ignoring any additional arguments.
259. Write a JavaScript program to decode a string of data encoded using base-64 encoding.
260. Write a JavaScript program to evaluate the binomial coefficients of two integers n and k.
261. Write a JavaScript program that returns true if the page bottom is visible, false otherwise.
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.
263. Write a JavaScript program to capitalize the first letter of a string.
264. Write a JavaScript program to capitalize the first letter of every word in a string.
265. Write a JavaScript program to chunk an array into smaller arrays of a specified size.
266. Write a JavaScript program to clamp a number within the inclusive range specified by the given boundary values a and b.
267. Write a JavaScript program to calculate the midpoint between two pairs of points.
268. Write a JavaScript program to find the index of an array item in a for loop.
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
Spread operator
const user = { name: 'Owen', age: 21 }; const admin = { admin: true, ...user }; console.log(admin);
It's possible to combine objects using the spread operator .... It lets you create copies of the key/value pairs of one object, and add them to another object. In this case, we create copies of the user object, and add them to the admin object. The admin object now contains the copied key/value pairs, which results in { admin: true, name: "Owen", age: 21 }.
Ref: https://bit.ly/323Y0P6
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- 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
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook