Found 9150 Articles for Object Oriented Programming

Disadvantages of using innerHTML in JavaScript

Abdul Rawoof
Updated on 26-Aug-2022 12:00:15

3K+ Views

HTML stands for Hyper Text Markup Language, through the HTML we can design a block of webpages. Html is a frontend markup language that is used to build the content of frontend pages. It means that we can build a structure of web pages. Through HTML we can design the content of any website. It means that we can create headings, buttons, paragraphs, headers, footers, links, etc for any website. Example let’s try to understand to implement a program − Basic of ... Read More

Convert the string of any base to integer in JavaScript

Ayush Gupta
Updated on 16-Sep-2019 08:19:08

154 Views

The parseInt function available in JavaScript has the following signature −parseInt(string, radix);Where, the paramters 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 numbner with base from 2 to 36 to integer using this method.Exampleconsole.log(parseInt("100", 10)) console.log(parseInt("10", 8)) console.log(parseInt("101", 2)) console.log(parseInt("2FF3", 16)) console.log(parseInt("ZZ", 36))Output100 8 ... Read More

Instanceof operator in JavaScript

Abdul Rawoof
Updated on 26-Aug-2022 11:59:38

1K+ Views

The Instanceof operator in JavaScript checks for the type of object at the run time environment. The result it returns is of Boolean type i.e., if the given input object is same as the object for which it is being checked, then it returns “true” or else it returns “false”. Syntax The syntax of Instanceof operator is shown below − var myVar = nameOfObject instanceof typeOfObject Instanceof operator is used in JavaScript for a unique purpose. As in JavaScript some of the variables are declared without mentioning the type of variable or the data type. In C, C++, Java ... Read More

What is "undefined x 1" in JavaScript?

Ayush Gupta
Updated on 16-Sep-2019 08:03:51

177 Views

This is not a feature of JavaScript but is Chrome's way of displaying uninitialized indexes in arrays (and array-like objects). For example, if you console.log the following −Exampleconsole.log(Array(100))Output[undefined × 100]This is better than printing [undefined, undefined, undefined,...] as it is more readable.

How do we check if an object is an array in Javascript?

Abdul Rawoof
Updated on 26-Aug-2022 11:59:58

286 Views

Array is a data type which can store multiple elements of similar data types. For example, if an array is declared as integer data type then it stores one or more elements of the integer data type. To check if the given object or to know the data type, we can use directly the typeof() method in JavaScript. Using typeof() method typeof() is a function which gives the type of the given object. The typeof() will return a string which is the data type of the given operand. The operand can be an object, a variable or a function. For ... Read More

In Javascript how to empty an array

Ayush Gupta
Updated on 07-Oct-2023 03:16:27

24K+ Views

There are multiple ways to clear/empty an array in JavaScript. You need to use them based on the context. Let us look at each of them. Assume we have an array defined as − let arr = [1, 'test', {}, 123.43]; Substituting with a new array − arr = []; This is the fastest way. This will set arr to a new array. This is perfect if you don't have any references from other places to the original arr. If you do, those references won't be updated and those places will continue to use the old array. Setting length prop ... Read More

Why is javascript called Richer Interface?

Ayush Gupta
Updated on 16-Sep-2019 07:40:36

204 Views

JavaScript allows you to add very advanced features to your web applications. For example, Drawing and manipulating graphicsAudio and Video APIs like HTMLMediaElement, the Web Audio API, and WebRTC allow you to do really interesting things with multimedia such as creating custom UI controls for playing audio and video, displaying text tracks like captions and subtitles along with your videos, grabbing video from your web camera to be manipulated via a canvas (see above) or displayed on someone else's computer in a web conference, or adding effects to audio tracks (such as gain, distortion, panning, etc).Device APIs are basically APIs ... Read More

Difference between regular functions and arrow functions in JavaScript

Ayush Gupta
Updated on 16-Sep-2019 07:36:51

777 Views

According to MDN, An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords. Arrow function expressions are ill suited as methods, and they cannot be used as constructors.There are 3 subtle differences in regular functions and arrow functions in JavaScript.No own this bindingsArrow functions do not have their own this value. The value of this inside an arrow function is always inherited from the enclosing scope.Examplethis.a = 100; let arrowFunc = () => {this.a = 150}; function regFunc() {    this.a = 200; ... Read More

Which algorithm does the JavaScript Array#sort() function use?

Ayush Gupta
Updated on 16-Sep-2019 07:28:03

965 Views

Javascript specification doesn't specify a particular algorithm to be used in the Array.sort implementation. This is left on the implementor to decide. So different JS engines use different sorting algorithms.Mozilla(Spider Monkey JS engine) uses mergeSort. You can see the code written for it in C in the Mozilla repository: https://dxr.mozilla.org/seamonkey/source/js/src/jsarray.cWebKit(Chrome, Safari, etc) do not directly use a sorting algorithm, instead they choose the algorithm based on element types and length of the array. For example, Numeric arrays use C++ Std library's quick sort function.Non-numeric arrays use merge sort.In some other cases it uses selection sort.It depends on the datatype and ... Read More

How would you deep copy an Object in Javascript?

Manisha Patil
Updated on 23-Aug-2022 14:41:09

252 Views

Clone often refers to copying a value from one place to another. We duplicate one value to another using JavaScript, which is known as cloning. In JavaScript, there are actually two different sorts of copying. The ability to distinguish between deep and shallow clones is something that every programmer, regardless of experience level, should understand. Since this essay is about deep clones, we shall investigate deep clones in detail. Any data type, including composite data types like arrays and JavaScript, as well as primitive data types (like string and number), can experience the concept of cloning. Therefore, we must understand ... Read More

Advertisements