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);
}