JavaScript

learn kro favicon img

JSON methods

Let’s say we have a complex object, and we’d like to convert it into a string, to send it over a network, or just to output it for logging purposes. Naturally, such a string should include all important properties. We could implement the conversion like this: …But in the process of development, new properties are …

JSON methods Read More »

learn kro favicon img

Date and time

Let’s meet a new built-in object: Date. It stores the date, time and provides methods for date/time management. For instance, we can use it to store creation/modification times, to measure time, or just to print out the current date. Creation To create a new Date object call new Date() with one of the following arguments:new Date() Without arguments – create …

Date and time Read More »

learn kro favicon img

Destructuring assignment

The two most used data structures in JavaScript are Object and Array. Although, when we pass those to a function, it may need not be an object/array as a whole. It may need individual pieces. Destructuring assignment is a special syntax that allows us to “unpack” arrays or objects into a bunch of variables, as sometimes that’s more convenient. …

Destructuring assignment Read More »

learn kro favicon img

Object.keys, values, entries

Let’s step away from the individual data structures and talk about the iterations over them. In the previous chapter we saw methods map.keys(), map.values(), map.entries(). These methods are generic, there is a common agreement to use them for data structures. If we ever create a data structure of our own, we should implement them too. They are supported …

Object.keys, values, entries Read More »

learn kro favicon img

WeakMap and WeakSet

As we know from the chapter Garbage collection, JavaScript engine keeps a value in memory while it is “reachable” and can potentially be used. For instance: Usually, properties of an object or elements of an array or another data structure are considered reachable and kept in memory while that data structure is in memory. For instance, …

WeakMap and WeakSet Read More »

learn kro favicon img

Map and Set

Till now, we’ve learned about the following complex data structures: But that’s not enough for real life. That’s why Map and Set also exist. Map Map is a collection of keyed data items, just like an Object. But the main difference is that Map allows keys of any type. Methods and properties are: For instance: As we can see, unlike objects, keys are …

Map and Set Read More »

learn kro favicon img

Iterables

Iterable objects are a generalization of arrays. That’s a concept that allows us to make any object useable in a for..of loop. Of course, Arrays are iterable. But there are many other built-in objects, that are iterable as well. For instance, strings are also iterable. If an object isn’t technically an array, but represents a collection (list, set) …

Iterables Read More »

learn kro favicon img

JavaScript Interview Questions (Part-2)

1. The following recursive code will cause a stack overflow if the array list is too large. How can you fix this and still retain the recursive pattern?

Answer:The potential stack overflow can be avoided by modifying the nextListItem function as follows:

The stack overflow is eliminated because the event loop handles the recursion, not …

JavaScript Interview Questions (Part-2) Read More »

learn kro favicon img

10 Days of JavaScript HackerRank Challenges

Solve 10 Days of JavaScript HackerRank Problems Today we’ve solved several JavaScript coding interview problems from hackerrank.com. Here we’ve presented 10 of them. 1. Functions Problem:Implement a function named factorial that has one parameter: an integer, . It must return the value of (i.e., factorial). Solution: 2. Let and Const Problem:1. Declare a constant variable, PI, and …

10 Days of JavaScript HackerRank Challenges Read More »