Radix Sort in JavaScript

Ayush Gupta
Updated on 16-Sep-2019 06:50:09

292 Views

The radix sort algorithm distributes integers into buckets based on a number's significant digit or value (the radix). The radix is based on the number system of the values of the arrays. Let us look at how it can be implemented −Examplefunction radixSort(arr) {    // Find the max number and multiply it by 10 to get a number    // with no. of digits of max + 1    const maxNum = Math.max(...arr) * 10;    let divisor = 10;    while (divisor < maxNum) {       // Create bucket arrays for each of 0-9     ... Read More

JavaScript Link: Hash vs javascript:void(0)

Smita Kapse
Updated on 13-Sep-2019 13:14:45

221 Views

Using “javascript:void(0)” is definitely better, since its faster. Try to run both the examples in Google Chrome with the developer tools. The “javascript:void(0)” method takes less time than the only #.Here’s the usage of “javascript: void(0)”:If inserting an expression into a web page results in an unwanted effect, then use JavaScript void to remove it. Adding “JavaScript:void(0)”, returns the undefined primitive value.The void operator is used to evaluate the given expression. After that, it returns undefined. It obtains the undefined primitive value, using void(0).The void(0) can be used with hyperlinks to obtain the undefined primitive valueExampleLive Demo     ... Read More

What is a Fat Arrow Function in JavaScript

Samual Sam
Updated on 13-Sep-2019 08:40:44

672 Views

Fat arrow function as the name suggests helps in decreasing line of code. The syntax => shows fat arrow. This also avoids you to write the keyword “function” repeatedly.Here’s the syntax:argument => expressionUse the following for more than one argument:(argument1 [, argument2]) => expressionLet’s compare a function with and without fat arrow:Function in JavaScriptvar rank = [7,8,9]; var display = rank.map(function(num) {    return num * num; });Fat Arrow function in JavaScriptvar rank= [7,8,9]; var display = rank.map((num) => num*num); document.write(arr)Arrow function definitely reduces the code lines.

Unset a JavaScript Variable

Sai Subramanyam
Updated on 13-Sep-2019 07:44:06

17K+ Views

To unset a variable in JavaScript, use the undefined. After that, use delete operator to completely remove it.Let’s try the code snippet again.var str = “Demo Text”; window.onscroll = function() {    var y = this.pageYOffset;    if(y > 200) {       document.write(nxt);       nxt = undefined; // unset      delete(nxt); // this removes the variable completely      document.write(nxt); // the result will be undefined } }

Best Way to Declare Multiple Variables in JavaScript

Amit Sharma
Updated on 13-Sep-2019 07:37:26

240 Views

Definitely, the following way of declaring multiple variables is more efficient:var variable1 = 5; var variable2 = 3.6; var variable3 = “Amit”;Suppose you need to add, remove, or update a variable, then you can easily do it.But with the following method, you need to do more changes. For example, on removing a variable, you need to remove the semi-colon. If it’s the first, then you need to add var to the second variable.var variable1 = 5, variable2 = 3.6, variable3 = “Amit”

Data Stored in var and How Its Content Changes in JavaScript

Amit Sharma
Updated on 13-Sep-2019 07:26:07

113 Views

JavaScript variables are not typed but their values do have a type. The same variable can be assigned new values.ExampleLive Demo                    var a;          document.write(typeof a+"\r");          a = true;          document.write(typeof a+"\r");          a = 5;          document.write(typeof a+"\r");          a = "web";          document.write(typeof a+"\r");          

Throw Unchecked Exception from a Static Block in Java

Maruthi Krishna
Updated on 12-Sep-2019 08:57:15

2K+ Views

A static block is a block of code with a static keyword. In general, these are used to initialize the static members. JVM executes static blocks before the main method at the time of class loading.Example Live Demopublic class MyClass {    static{       System.out.println("Hello this is a static block");    }    public static void main(String args[]){       System.out.println("This is main method");    } }OutputHello this is a static block This is main methodExceptions in static blockJust like any other method in Java when an exception occurs in static block you can handle it using try-catch ... Read More

Throw Exception Without Breaking For Loop in Java

Maruthi Krishna
Updated on 12-Sep-2019 08:54:22

9K+ Views

Whenever an exception occurred in a loop the control gets out of the loop, by handling the exception the statements after the catch block in the method will get executed. But, the loop breaks.Example Live Demopublic class ExceptionInLoop{    public static void sampleMethod(){       String str[] = {"Mango", "Apple", "Banana", "Grapes", "Oranges"};          try {             for(int i=0; i

Give a Warning for Non-JavaScript Browsers

Giri Raju
Updated on 12-Sep-2019 08:47:00

284 Views

To let users know about non-JavaScript web browsers, use the tag. The HTML tag is used to handle the browsers, which do recognize tag but do not support scripting. This tag is used to display alternate text messageHere’s an example,           HTML noscript Tag                                              Your browser does not support JavaScript!          

Can We Override a Catch Block in Java

Maruthi Krishna
Updated on 12-Sep-2019 08:46:56

1K+ Views

DescriptionWhen a piece of code in particular method throws an exception, and is handled using try-catch pair. If we are calling this method from another one and, the calling line is wrapped within try-catch pair. Now, how can I override the catch block by the catch block of the calling method.When a piece of code in a method throws an exception (compile time) we must either handle it by wrapping it within the try-catch pair or, throw it (postpone) to the calling method using the throws keyword else a compile time error occurs.In the following Java example the code in ... Read More

Advertisements