Found 9150 Articles for Object Oriented Programming

Why doesn't JavaScript support multithreading?

Ayush Gupta
Updated on 02-Dec-2019 06:04:38

526 Views

JavaScript used to be single-threaded. It runs using what is called an event loop.The Event Loop has one simple job — to monitor the Call Stack and the Callback Queue. If the Call Stack is empty, it will take the first event from the queue and will push it to the Call Stack, which effectively runs it.JS in browsers doesn't support multithreading in the event loop as it is not needed for 99.999% of the websites. The event loop handles everything seamlessly.For the remaining apps, devs can use web workers. Web Workers are a simple means for web content to ... Read More

How to test if a letter in a string is uppercase or lowercase using javascript?

Ayush Gupta
Updated on 02-Dec-2019 05:59:26

8K+ Views

To test if a letter in a string is uppercase or lowercase using javascript, you can simply convert the char to its respective case and see the result.Examplefunction checkCase(ch) {    if (!isNaN(ch * 1)){       return 'ch is numeric';    }     else {       if (ch == ch.toUpperCase()) {          return 'upper case';       }       if (ch == ch.toLowerCase()){          return 'lower case';       }    } } console.log(checkCase('a')) console.log(checkCase('A')) console.log(checkCase('1'))OutputThis will give the output −lower case upper case ch is numeric

What Is a JavaScript Framework?

Ayush Gupta
Updated on 02-Dec-2019 05:57:56

1K+ Views

JS frameworks are JavaScript code libraries that have pre-written code to use for routine programming features and tasks. It is literally a framework to build websites or web applications around.For example, in plain JS, you have to manually update the DOM using DOM APIs for setting styles updating content, etc.JS frameworks can help automate this repetitive task using features like 2-way binding and templating.Frameworks have their own way of doing things. For example, Angular is a popular JS framework that comes with many features like dependency injection, routing, etc and has its own way of building an application using it. ... Read More

What are the differences between clientHeight() and offsetHeight() in javascript?

Ayush Gupta
Updated on 02-Dec-2019 05:57:09

326 Views

You can use 2 properties, clientHeight and offsetHeight to get the height of the div.clientHeight includes padding of the div.offsetHeight includes padding, scrollBar, and borders of the div.ExampleFor example, if you have the following HTML −You can get the height using −const height = document.querySelector('#myDiv').offsetHeight console.log(height)OutputThis will give the output −400

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

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

262 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 }

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

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

309 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, Python to get Javascript V8 speed?

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

130 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.

Converting strings to numbers with vanilla JavaScript

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

204 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

804 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

If a DOM Element is removed, are its listeners also 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.

Advertisements