Get a Subset of a JavaScript Object's Properties

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

317 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 the name and age, you can create the new objects using −const {name, age} = person; const selectedObj = {name, age}; console.log(selectedObj);OutputThis will give the output −{    name: 'John',    age: 40 }

What Blocks Ruby and Python from Achieving JavaScript V8 Speed

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

135 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 optimization effort on these languages.

Convert Strings to Numbers with Vanilla JavaScript

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

214 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 between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the string.So we can pass the string and the radix and convert any number with base from 2 to 36 to integer using this method. For example, Exampleconsole.log(parseInt("100", 10)) console.log(parseInt("10", 8)) console.log(parseInt("101", 2)) console.log(parseInt("2FF3", 16)) ... Read More

Jasmine JavaScript Testing: toBe vs toEqual

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

821 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 reference equility", () => {       let arr = [1, 2, 3];       let arr2 = arr       // Runs successfully       expect(arr).toBe(arr2);       // Fails as references are not equal       expect(arr).toBe([1, 2, 3]);    }); });OutputThis ... Read More

Are DOM Element Listeners Removed from Memory in JavaScript?

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

3K+ 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 from memory.

Difference Between throw new Error and throw SomeObject in JavaScript

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

564 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 allow any further code execution from the try block, ie same as throw new Error.

Differences Between Deferreds, Promises, and Futures in JavaScript

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 extends Promise) can resolve itself, while a promise might not be able to do so. This can also be thought of as a promise that'll always succeed only.A promise is a placeholder for a result which is initially unknown while a deferred represents the computation that results in the value.Read More

Object and Class in Perl

Mohd Mohtashim
Updated on 29-Nov-2019 12:18:19

184 Views

There are three main terms, explained from the point of view of how Perl handles objects. The terms are object, class, and method.An object within Perl is merely a reference to a data type that knows what class it belongs to. The object is stored as a reference in a scalar variable. Because a scalar only contains a reference to the object, the same scalar can hold different objects in different classes.A class within Perl is a package that contains the corresponding methods required to create and manipulate objects.A method within Perl is a subroutine, defined with the package. The first argument to ... Read More

Send Email with Attachment using Perl

Mohd Mohtashim
Updated on 29-Nov-2019 12:15:51

2K+ Views

If you want to send an attachment in your email using Perl, then following script serves the purpose −#!/usr/bin/perl use MIME::Lite; $to = 'abcd@gmail.com'; $cc = 'efgh@mail.com'; $from = 'webmaster@yourdomain.com'; $subject = 'Test Email'; $message = 'This is test email sent by Perl Script'; $msg = MIME::Lite-=>new(    From => $from,    To => $to,    Cc => $cc,    Subject => $subject,    Type => 'multipart/mixed' ); # Add your text message. $msg->attach(    Type => 'text',    Data => $message ); # Specify your file as attachement. $msg->attach(Type => 'image/gif',    Path => '/tmp/logo.gif',    Filename => 'logo.gif', ... Read More

Sending an HTML Message Using Perl

Mohd Mohtashim
Updated on 29-Nov-2019 12:14:02

660 Views

If you want to send HTML formatted email using sendmail, then you simply need to add Content-type: text/html in the header part of the email as follows −#!/usr/bin/perl $to = 'abcd@gmail.com'; $from = 'webmaster@yourdomain.com'; $subject = 'Test Email'; $message = 'This is test email sent by Perl Script'; open(MAIL, "|/usr/sbin/sendmail -t"); # Email Header print MAIL "To: $to"; print MAIL "From: $from"; print MAIL "Subject: $subject"; print MAIL "Content-type: text/html"; # Email Body print MAIL $message; close(MAIL); print "Email Sent Successfully";

Advertisements