JavaScript Flashcards

1
Q

spread operator es6

A
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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how to add item at begin and end of array? js

A
Array = [“1”,”2”,”3”]
arrary = array.push("end")
array = array.unshift("start")
Console log array 
start,1,2,3,end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how to create a private variable in JS?

A
function secretVariable(){
var private = "secret";
return function (){ return private;}
}
var getSecretVariable = secretVarialbe();
console.log(getSecretVariable());
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what are closures in JS?

A

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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is scope in JS?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly