Functions , Objects and "this" and how they work

//Copy and paste this post into your editor or browser console and follow the results. //A very interesting thing I discovered about an Array is that the elements do not have to be of the same type. Arrays allows us to store multiple elements of different types such as numbers, booleans, objects, functions, and strings, and you can call a function, boolean, number, object, and strings by just listing its number in brackets. //Example //Copy this array into your console and run: var arr = [ 1, false, { name: "Imhotep", address: '1003 Main Street' }, function(name){ var greeting= "hello "; console.log(greeting + name); }, "hello" ]; //Now my array contains numbers, booleans, objects and functions and a string. I can call any element I wish by: console.log(arr[0]); console.log(arr[1]); console.log(arr[2]); console.log(arr[3]); console.log(arr[4]); //or I can just call the array console.log(arr); //This will give all the elements in the array
1 Like