spread operator es6
Spread operator es6 Array = [“1”,”2”,”3”] Var x = [“start”, …array]; Var x = […array, “end”]; Console log array Start,1,2,3,end
or
Var x = [“start”, …array, “end”];
how to add item at begin and end of array? js
Array = [“1”,”2”,”3”]
arrary = array.push("end")
array = array.unshift("start")
Console log array
start,1,2,3,endhow to create a private variable in JS?
function secretVariable(){
var private = "secret";
return function (){ return private;}
}
var getSecretVariable = secretVarialbe();
console.log(getSecretVariable());what are closures in JS?
Closure means that an inner function always has access to the vars and parameters of its outer function, even after the outer function has returned.
function buildName(name) {
var greeting = "Hello, " + name + "!";
var sayName = function() {
var welcome = greeting + " Welcome!";
console.log(greeting);
};
return sayName;
}var sayMyName = buildName("John");
sayMyName(); // Hello, John.what is scope in JS?
Scope in JavaScript refers to the current context of code, which determines the accessibility of variables to JavaScript. The two types of scope are local and global: Global variables are those declared outside of a block. Local variables are those declared inside of a block