ES6 JS Flashcards
What is a code block? What are some examples of a code block?
A code block is a line of code within curly braces such as after an if statement, function call/function definition css ruleset, loop conditionals
What does block scope mean?
It means that within a code block that would be the block scope. if the block scope is local then it pertains to inside the curly braces other wise global means the whole js file.
What is the scope of a variable declared with const or let?
both are block scoped and read-only, the content is immutable where as let, if an object can change reference data.
What is the difference between let and const?
Const cannot be reassigned, variable declared by let are mutable so the values can change, const needs to be initialized.
Why is it possible to .push() a new value into a const variable that points to an Array
The array can add elements it does not change the value. however because it is const it cannot be reassigned as it is immutable
How should you decide on which type of declaration to use?
if u do not wish to reassign values to the variable use const, within for loops use let unless it is a for..of loop then use const.
What is the syntax for writing a template literal?
` ` - using back ticks,
${variable_name } - use this syntax to substitute a variable within it
What is “string interpolation”?
It is when a a template literal has substitutions and string
What is destructuring, conceptually?
Taking properties from an object or values from an array and creating individual variables.
What is the syntax for Object destructuring?
let person = { firstName: DJ }
THIS IS THE SYNTAX: let {firstName} = person;
or const{(propertyName:(name of variable u choose)} = person; both will have different
You have a keyword either let, const, or var within an object literal
What is the syntax for Array destructuring?
it is a keyword let, const, or var followed by array literal and then intialized to an array. Ex: const array = [1,2,3] const [num1, num2, num 3] = array;
console.log(num1) is 1;
How can you tell the difference between destructuring and creating Object/Array literals?
Creating object/array means it is on the right side of the assignment operator
Destructuring means it is the keyword let, const, var followed by object/array literal and then whatever is being assigned to that
CREATE: const person = [ ] || { };
Destructuring: const {you} || [you] = [ ] || { };
What is the syntax for defining an arrow function?
It will be parameter followed by arrow then code let variable_name = () => some code;
When an arrow function’s body is left without curly braces, what changes in its functionality?
It does not need the return key word after the arrow
How is the value of this determined within an arrow function?
It inherits this from the function it is in.
WHAT IS CLI?
CommandLine InterFace
What is GUI?
Graphical User Interface, The user can move and interact with it
Give at least one USE case for each man cat ls pwd echo touch mkdir mv rm cp
man - manual for each command line tool
cat - prints the content of file
ls - looks at the directories list
pwd -Prints the working directory can create files within the pwd
echo - can put whats printed on CLI in a file
touch - gives a time stamp
mkdir - can make a new directory or more than one
mv - used to change a file name or move file
rm - can delete files
cp - copy the contents of one file into another one
what is Node.js
It lets javascript run outside of the browser