Found 6710 Articles for Javascript

what is the significance of finally in javascript?

Abdul Rawoof
Updated on 25-Aug-2022 12:19:24

1K+ Views

In JavaScript finally is a block of code or statements that are executed in all cases while handling errors with a try and catch block whenever used. These try, catch and finally blocks in JavaScript will execute the code that is prone to error and may cause the program to behave incorrectly (terminate abruptly). This finally block is positioned after the try and catch blocks, will unquestionably be executed if either of those blocks, try or catch, is ever executed. The finally block allows us to define the actions that must be performed regardless of whether some code succeeds or ... Read More

what is the main difference between '=' and '==' operators in javascript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

252 Views

The use of  "=" operator is that it assigns value from right to left, whereas "==" shows whether the given values are equal or not.In the following example variables x and y were assigned values using "=" operator and their magnitudes were checked using "==" operator.Example Live Demo    var x = 5;    var y = "6";    document.write(x);    document.getElementById("equal").innerHTML =    (x == y); Outputfalse 5

Write the main difference between '==' and '===' operators in javascript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

184 Views

The difference between '==' and '===' is that former checks only value but the latter checks value and also data type(String, Boolean etc).The following example gives whether values assigned are equal or not irrespective of datatype. a) "==" operator(checks equality) Example Live Demo    var x = 5;    var y = 5;    var z = 6;    document.getElementById("strict").innerHTML =    (x == y) + "" + (x == z); Outputtrue falseb) '===' operator (Checks strict equality)     "==="  operator gives true if and only if both value and data type are equal.If not it returns false.In ... Read More

Write a program to find the index of particular element in an array in javascript?

Vivek Verma
Updated on 29-Aug-2022 08:05:40

1K+ Views

Array is an object which contains multiple values of the same datatype in a sequential order. In other words, we can say that an array is a special type of object in the JavaScript. SyntaxWe can create an array in two ways in JavaScript. The syntax are given below − var arr = [val1, val2, …]; var arr = new Array(“val1”, “val2”, …) Now let us look at a simple JavaScript program to create an array and print its index values − var arr = [1, 2, 3, 4, 5]; document.write(arr[0]); Here, the program returns the content in ... Read More

TypedArray.toString() function in JavaScript

Samual Sam
Updated on 25-Jun-2020 13:32:31

74 Views

The toString() function of the TypedArray object returns a string representing the contents of the typed array.SyntaxIts Syntax is as followstypedArray.toString();Example Live Demo    JavaScript Example           var typedArray = new Int32Array([111, 56, 62, 40, 75, 36, 617, 2, 139, 827 ]);       var result = typedArray.toString();       document.write("Contents of the typed array: "+result);     OutputContents of the typed array: 111,56,62,40,75,36,617,2,139,827

TypedArray.subarray() function in JavaScript

karthikeya Boyini
Updated on 25-Jun-2020 13:32:43

78 Views

The subarray() function of the TypedArray object returns portion of the current array. It accepts two numbers representing the start and end of the sub array.SyntaxIts Syntax is as followstypedArray.subarray(5, 9)Example Live Demo    JavaScript Example           var typedArray = new Int32Array([111, 56, 62, 40, 75, 36, 617, 2, 139, 827 ]);       var result = typedArray.subarray(3, 7);       document.write("Contents of the typed array: "+result);     OutputContents of the typed array: 40,75,36,617

TypedArray.values() function in JavaScript

Samual Sam
Updated on 25-Jun-2020 13:33:13

85 Views

The values() function of the TypedArray returns an iterator object which holds the values of the typed array. The next() method returns the next element in the iterator object.SyntaxIts Syntax is as followstypedArray.values()Example Live Demo    JavaScript Example           var typedArray = new Int32Array([11, 5, 13, 4, 15, 3, 17, 2, 19, 8 ]);       var iterator = typedArray.values();       document.write("Contents of the typed array: ");       for(i=0; i

TypedArray.sort() function in JavaScript

karthikeya Boyini
Updated on 25-Jun-2020 13:33:45

122 Views

The sort() method of the Typed Array object arranges the elements of the array in ascending order and returns it.SyntaxIts Syntax is as followsarrayBuffer.sort()Example Live Demo    JavaScript Array every Method           var typedArray = new Int32Array([11, 5, 13, 4, 15, 3, 17, 2, 19, 8 ]);       document.write("Contents of the typed array: "+typedArray);       document.write("");       var resultantArray = typedArray.sort();       document.write("Resultant Array: "+resultantArray);     OutputContents of the typed array: 11,5,13,4,15,3,17,2,19,8 Resultant Array: 2,3,4,5,8,11,13,15,17,19

TypedArray.slice() function in JavaScript

Samual Sam
Updated on 25-Jun-2020 13:36:07

92 Views

The slice() method of the typed array object returns a portion or, chunk from the array buffer (as a separate object). It accepts two integer arguments representing the start and end of the portion of the array to be returned.SyntaxIts Syntax is as followsarrayBuffer.slice(3, 8)Example Live Demo    JavaScript Array every Method           var typedArray = new Int32Array([11, 5, 13, 4, 15, 3, 17, 2, 19, 8 ]);       document.write("Contents of the typed array: "+typedArray);       document.write("");       var resultantArray = typedArray.slice(2, 7);       document.write("Resultant Array: "+resultantArray);     OutputContents of the typed array: 11,5,13,4,15,3,17,2,19,8 ResultantArray: 13,4,15,3,1

TypedArray.set() function in JavaScript

karthikeya Boyini
Updated on 25-Jun-2020 13:36:31

47 Views

The set() function of TypedArray object accepts an array a number representing the index and copies the contents of the specified array in to the current array starting at the given index.SyntaxIts Syntax is as followstypedArray.set()Example Live Demo    JavaScript Array every Method           var typedArray1 = new Int32Array([11, 5, 13, 4, 15, 3, 17, 2, 19, 8 ]);       document.write("Contents of the typed array: "+typedArray1);       document.write("");       var typedArray2 = new Int32Array([110, 215, 316, 916, 616, 117, 311 ]);       typedArray1.set(typedArray2, 3);       document.write("Result: "+typedArray1);     OutputContents of the typed array: 11,5,13,4,15,3,17,2,19,8 Result: 11,5,13,110,215,316,916,616,117,311

Advertisements