JSON methods

learn kro favicon img

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 … Read more

Date and time

learn kro favicon img

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 … Read more

Destructuring assignment

learn kro favicon img

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. … Read more

Object.keys, values, entries

learn kro favicon img

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 … Read more

WeakMap and WeakSet

learn kro favicon img

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, … Read more

Map and Set

learn kro favicon img

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 … Read more

Iterables

learn kro favicon img

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) … Read more

JavaScript Interview Questions (Part-2)

learn kro favicon img

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? var list = readHugeList();var nextListItem = function() { var item = list.pop(); if (item) { // process the list item… nextListItem(); }}; Answer:The potential stack overflow can … Read more

JavaScript Interview Questions (Part-1)

learn kro favicon img

1. difference between Function.prototype.apply and Function.prototype.call? The only difference between apply and call is how we pass the arguments in the function being called. In apply we pass the arguments as an array and in call we pass the arguments directly in the argument list. Example: const obj1 = {result:0}; const obj2 = {result:0}; function … Read more

10 Days of JavaScript HackerRank Challenges

learn kro favicon img

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 … Read more