ES2015 Flashcards
var hello = ‘hello’;
function sayHi() { var hello = 'hi'; console.log(hello); }
sayHi();
‘hi”
var student = { name: 'Ken' }; var student = { name: 'James' };
console.log(student);
‘James’
var hello = ‘hello’;
function sayHi() { var hello = 'hi'; console.log(hello); }
sayHi();
console.log(hello)
hi
hello
const student = { name: 'Ken' }; var student = { name: 'James' };
console.log(student);
give error
you can declare a let or const variable with the same name in ____________
a different scope
RETURNS
(function () { const student = { name: 'James' };
function createStudent(name) { const student = { name: name }; return student; }
console.log(createStudent(‘Ken’));
console.log(student);
})();
Ken
James
use ______ when you need to assign a variable , or scope a variable at the block level
let
use ______ when you don’t want a variable value to change through out the project
const
let strToSearch = ‘a-really-long-hyphenated-string’;
console. log(/^a-really/.test(strToSearch)); // test string w/ regular expression
console. log(strToSearch.indexOf(‘a-really’) === 0); // indexOf
console. log(strToSearch.startsWith(‘a-really’)); // startsWith
all true
let strToSearch = ‘a-really-long-hyphenated-string’;
console. log(/hyphenated-string$/.test(strToSearch)); // test string w/ regular expression
console. log(strToSearch.indexOf(‘hyphenated-string’) === strToSearch.length - ‘hyphenated-string’.length); // indexOf
console. log(strToSearch.endsWith(‘hyphenated-string’)); // endsWith
all true
let strToSearch = 'a-really-long-hyphenated-string'; console.log(strToSearch.startsWith('a-really', 5)); // startsWith
false
starts at index 5
let strToSearch = 'a-really-long-hyphenated-string'; console.log(strToSearch.endsWith('hyphenated-string', 22)); // endsWith
false
let and const type variables can be accessed from ______.
nested scope
let and const are best used for ______.
block level scopting
MAKE TO ARROW FUN
this.getKeys = function () {
return Object.keys(this);
}
this.getKeys = () => {
return Object.keys(this);
}
ADD DEFAULT VAULES FOR NAME, TIMEOFDAY
function greet(name, timeOfDay) { console.log(`Good ${timeOfDay}, ${name}!`); }
function greet(name = "steve", timeOfDay = "day") { console.log(`Good ${timeOfDay}, ${name}!`); }
an arrow function is bound to it’s ______ scope
parent
Given a function that has two default parameters. You want to keep the default value of the first parameter but override the default value of the second parameter. When calling the function, what value should the first parameter be?
undefined
block level is any piece of code surrounded in ________
{}
braces
var i; // i is declared in the containing scope for(i = 0; i < 10; i++) { ... // some code } return i; // accessible or no?
accessible here
for(var i = 0; i< 10; i++){
}
return i; // i// accessible or no?
not accessible here in block scoped language