Ayush Gupta has Published 541 Articles

How to create a new object with only a subset of properties using vanilla Javascript

Ayush Gupta

Ayush Gupta

Updated on 02-Dec-2019 05:54:32

194 Views

To get a subset of object's properties and create a new object out of those properties, use object destructuring and property shorthand. For example, You have the following object −Exampleconst person = {    name: 'John',    age: 40,    city: 'LA',    school: 'High School' }And you only want ... Read More

How to get a subset of a javascript object's properties?

Ayush Gupta

Ayush Gupta

Updated on 02-Dec-2019 05:53:16

205 Views

To get a subset of object's properties and create a new object out of those properties, use object destructuring and property shorthand. For example, You have the following object −Exampleconst person = {    name: 'John',    age: 40,    city: 'LA',    school: 'High School' }And you only want ... Read More

What blocks Ruby, Python to get Javascript V8 speed?

Ayush Gupta

Ayush Gupta

Updated on 02-Dec-2019 05:51:42

78 Views

Nothing. They can get to V8 speed if proper investments are made in optimizing those language engines as are made for JS by Google in the V8 project.This is all really a matter of how much push is provided to the language by sponsoring organizations to further the development and ... Read More

Converting strings to numbers with vanilla JavaScript

Ayush Gupta

Ayush Gupta

Updated on 02-Dec-2019 05:41:54

124 Views

The parseInt function available in JavaScript has the following signature −SyntaxparseInt(string, radix);Where the parameters are the following −string − The value to parse. If this argument is not a string, then it is converted to one using the ToString method. Leading whitespace in this argument is ignored.radix − An integer ... Read More

Jasmine JavaScript Testing - toBe vs toEqual

Ayush Gupta

Ayush Gupta

Updated on 02-Dec-2019 05:39:23

583 Views

Arrays can be compared in 2 ways −They refer to the same array object in memory.They may refer to different objects but their contents are all equal.ExampleFor case 1, jasmine provides the toBe method. This checks for reference. For example, describe("Array Equality", () => {    it("should check for array ... Read More

If a DOM Element is removed, are its listeners also removed from memory in javascript?

Ayush Gupta

Ayush Gupta

Updated on 02-Dec-2019 05:35:14

2K+ Views

In modern browsers, if a DOM Element is removed, its listeners are also removed from memory in javascript.Note that this will happen ONLY if the element is reference-free. Or in other words, it doesn't have any reference and can be garbage collected. Only then its event listeners will be removed ... Read More

What is the difference between 'throw new Error' and 'throw someObject' in javascript?

Ayush Gupta

Ayush Gupta

Updated on 02-Dec-2019 05:34:13

455 Views

The difference between 'throw new Error' and 'throw someObject' in javascript is that throw new Error wraps the error passed to it in the following format −{    name: 'Error',    message: 'Whatever you pass in the constructor' }The throw someObject will throw the object as is and will not ... Read More

What are the differences between Deferreds, Promises and Futures in javascript?

Ayush Gupta

Ayush Gupta

Updated on 02-Dec-2019 05:31:52

1K+ Views

Future is an old term that is same as promise.A promise represents a value that is not yet known. This can better be understood as a proxy for a value not necessarily known when the promise is created.A deferred represents work that is not yet finished. A deferred (which generally ... Read More

What is the reason to choose jasmine over jest?

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 12:31:17

64 Views

There is no solid reason to choose jasmine over jest. Both are excellent libraries that have been around for a while and have an opinionated way of doing things that are quite similar. Jest is built on top of jasmine.One reason why you might choose jasmine over jest is that ... Read More

What is the use of sinon.js?

Ayush Gupta

Ayush Gupta

Updated on 27-Nov-2019 12:21:19

406 Views

SinonJS provides stand-alone test spies, stubs and mocks. It is a library that we can use to create object mocks for unit testing.Spies − Fake functions that we can use to track executions.Stubs −Functions replacements from which we can return whatever we want or have our functions work in a ... Read More

Advertisements