JavaScript

Splice function in JavaScript

The splice function in JavaScript is used for adding, removing and returning elements from an array. Let us suppose we have an array var a=new Array(1,2,3,4,5); Splice with one parameter: This returns the elements of the array starting at the parameter. var b=a.splice(0); b=1,2,3,4,5. a=var b=a.splice(2): b=3,4,5 a=1,2 Splice with 2…

Sort Function in JavaScript Arrays

The sort function in JavaScript Arrays allows performs sorting of array elements. Like all of JavaScript this function is remarkably flexible as well. Let us say we want to sort an array. var a=Array(4,5,3,-2); To sort you call a.sort(); This will sort the array numerically. -2,3,4,5 To change the sorting mode we…

Arrays in JavaScript

An Array in JavaScript is a collection of items. The items can be accessed and modified. The whole array can be passed as a parameter to some function. Since JavaScript is typeless we can store data of any kind. The array automatically creates a variable called length which automatically gives the size…

Functions in JavaScript

Functions in JavaScript bring out the real flexibility of the language. Functions can be stored in variables, defined at runtime. Even inbuilt functions can be redefined. Declaring functions function add(a,b) { return a+b; } a and b are the 2 parameters. I can call this function in the following way add(3,4).…

Numbers and Operations on Numbers in JavaScript

A Number type A numeric value in JavaScript is a double-precision, 64-bit binary format, IEEE 754 value. The storage format is: 0-51: fraction, 52-62: exponent, bit 63 is sign.  The highest value that can be represented internally is 253 which is 9,007,199,254,740,994. Then they are stored as powers of 2(2exponent).  Special values…