Class Keyword in JavaScript

Ayush Gupta
Updated on 18-Sep-2019 13:14:06

235 Views

JavaScript classes, introduced in ES6, are syntactical sugar over JavaScript prototype-based inheritance. Classes are in fact "special functions". You can define classes in JavaScript using the class keyword using the following syntax −class Person {    // Constructor for this class    constructor(name) {       this.name = name;    }    // an instance method on this class    displayName() {       console.log(this.name)    } }This is essentially equivalent to the following declaration −let Person = function(name) {    this.name = name; } Person.prototype.displayName = function() {    console.log(this.name) }This class can also be written as ... Read More

JavaScript RegExp with Metacharacter

Ayush Gupta
Updated on 18-Sep-2019 12:32:45

247 Views

The \W metacharacter is used to find a non-word character.A word character is a character from a-z, A-Z, 0-9, including the _ (underscore) character.Example// Containing any non word character: console.log(/\W/.test(" ")) console.log(/\W/.test(".!@#")) // Not containing non word characters: console.log(/\W/.test("a")) console.log(/\W/.test("B")) console.log(/\W/.test("9")) console.log(/\W/.test("_"))Outputtrue true false false false false

JavaScript RegExp s Metacharacter

Ayush Gupta
Updated on 18-Sep-2019 12:26:19

135 Views

The \s metacharacter is used to find a whitespace character.A whitespace character can be −A space characterA tab characterA carriage return characterA new line characterA vertical tab characterA form feed characterExample// Not containing any white spaces: console.log(/\s/.test("1")) console.log(/\s/.test("test")) // Containing whitespace characters: console.log(/\s/.test(" ")) console.log(/\s/.test("a\tb")) console.log(/\s/.test("mn"))Outputfalse false true true true

Difference Between Length of Array and Size of ArrayList in Java

Nitin Sharma
Updated on 18-Sep-2019 12:23:03

629 Views

In collections, one of the main functional requirement is to get the number of elements which are get stored in our collection so that one can decide whether to put more elements in it or not. Also, the number of elements is also required for iteration of collection.As we know Array and Arraylist both are used to store elements but both have different defined methods in order to know the number of elements stored in it.The array has a length method that provides the number of elements can be stored or in simple words capacity of the Array. Also, the ... Read More

Difference Between Definition and Declaration in Java

Nitin Sharma
Updated on 18-Sep-2019 12:14:17

3K+ Views

For the difference between definition and declaration, one should consider their literal meaning first which includes Declare means to announce or proclaim while Define means to describe some entity.The following are the important differences between the Definition and the Declaration.Sr. No.KeyDeclarationDefinition1ConceptThe concept of declaration includes informing the compiler about properties of the variable such as its name, type of value it holds and the initial value if any it takes.While the definition is basically the actual implementation and memory location of function and about memory for the variable is allocated during the definition of the variable.2Exception in CBoth declaration and ... Read More

Difference Between Daemon Threads and User Threads in Java

Nitin Sharma
Updated on 18-Sep-2019 12:10:14

1K+ Views

As we know java is a language that supports multi threading and on the basis of nature threads in java are classified into two types Daemon thread and User thread.The following are the important differences between Daemon Threads and User Threads.Sr. No.KeyDaemon ThreadsUser Threads1NatureDaemon thread is low in priority i.e JVM does not care much about these types of threads.User threads are recognized as high priority thread i.e. JVM will wait for any active user thread to get completed.2CPU availabilityIt is not guaranteed that Daemon thread always gets CPU usage whenever it requires due to its low priority.User thread always ... Read More

Remove All Elements from a Set in JavaScript

Ayush Gupta
Updated on 18-Sep-2019 12:03:47

452 Views

The Set class in JavaScript provides a clear method to remove all elements from a given set object. This method can be used as follows −Examplelet mySet = new Set(); mySet.add(1); mySet.add(2); mySet.add(1); mySet.add(3); mySet.add("a"); console.log(mySet) mySet.clear(); console.log(mySet)OutputSet { 1, 2, 3, 'a' } Set { }You can also individually remove the elements by iterating over them.Examplelet mySet = new Set(); mySet.add(1); mySet.add(2); mySet.add(1); mySet.add(3); mySet.add("a"); console.log(mySet) for(let i of mySet) {    console.log(i)    mySet.delete(i) } console.log(mySet)OutputSet { 1, 2, 3, 'a' } Set { }

Ways to Create a Set in JavaScript

Ayush Gupta
Updated on 18-Sep-2019 12:01:15

154 Views

A set is an abstract data type that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set.Ways to create a set in js−1. Using empty Set constructorlet mySet = new Set(); mySet.add(1); mySet.add(1); console.log(mySet)OutputSet { 1 } 2. Passing an iterable to the constructorThe set constructor accepts an iterable object(list, set, etc) using which it constructs a new set.Examplelet mySet ... Read More

What are JavaScript Sets

Ayush Gupta
Updated on 18-Sep-2019 11:57:00

208 Views

A set is an abstract data type that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set.You should use sets, whenever you want to store unique elements in a container for which the order doesn't matter and you mainly want to use it to check for membership of different objects. Sets are also useful when you want to perform operations ... Read More

Difference Between Compile-Time Errors and Runtime Errors in C

Nitin Sharma
Updated on 18-Sep-2019 11:49:02

2K+ Views

Error or exception is something that refers to the interruption of code execution due to which the expected outcome could not be attained to the end-user.On the basis of the event when an error is generated or identified we can classify them as Compile time error and runtime error.The following are the important differences between Compile Time Errors and Runtime Errors.Sr. No.KeyCompile Time ErrorsRuntime Errors1ReferenceCompile-time errors are generally referred to the error corresponding to syntax or semantics.Runtime errors on the other hand refer to the error encountered during the execution of code at runtime.2DetectionCompile-time errors get detected by compiler at ... Read More

Advertisements