The map function of a JavaScript array applies a certain method to all elements and creates an array. Example 1 The following method call will change all values to positive function f() { var a = Array(1,2,-3,4); var b = a.map(Math.abs); } Output: a=1,2,-3,4 b=1,2,3,4 Example 2 The following method call will…
1. concat function merges arrays and returns the combined array Example 1 var a = Array(1, 2, 3); var b = Array(4, 5, 6); var c=Array(7,8,9); var d = a.concat(b, c); a=1,2,3 b=4,5,6 c=7,8,9 d=1,2,3,4,5,6,7,8,9 concat does not modify the original arrays and we can concat as many arrays as…
JavaScript has two scopes local and global. Variables inside a function are local if defined with the prefix var, if not it becomes global. Consider the following code: function f1() { x = 10; } function f() { f1(); x = x + 5; alert(x); } If I call the function…
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).…