Senior Side Flashcards
es6-const-let
What is a code block? What are some examples of a code block?
A code block are lines of code which are grouped together by curly braces. Some examples are for loops, if statements, and functions.
es6-const-let
What does block scope mean?
It means that the code/variable will not be accessible outside the code block (curly braces).
es6-const-let
What is the scope of a variable declared with const or let?
Block scoped
Var = function scope
es6-const-let
What is the difference between let and const?
Let can be updated, but not redeclared. Const can’t be updated nor redeclared.
Const must be initialized when it’s defined
Similarity = both const and let are blocked scoped and they’re not initialized with undefined like var keyword.
es6-const-let
Why is it possible to .push() a new value into a const variable that points to an Array?
We can change the values, in this case add, of a const variable, but we can’t reassign or redeclare it.
es6-const-let
How should you decide on which type of declaration to use?
Const variables are for things that don’t change values, let is for values that are meant to manipulated or changed.
good code doesn’t reassing var
es6-template-literals
What is the syntax for writing a template literal?
Replace all quotes for a string with backticks ( ` ` )
Can contain strings and any JavaScript expressions (anything that returns a value): ${firstName.toUpperCase()}
es6-template-literals
What is “string interpolation”?
Having expression/variables values substituted in a string. EX: ${variable_name}
es6-destructuring
What is destructuring, conceptually?
Assigning a variable to the value extracted from an object property or an array index
es6-destructuring
What is the syntax for Object destructuring?
const keyword, then curly braces { }, property key names, then equal signs = , then object name you’re destructuring from, use OR || to avoid errors after name
es6-destructuring
What is the syntax for Array destructuring?
const keyword, then square brackets [ ], elements you want, then equal signs = array name that is destructured, use OR || to avoid errors after name
es6-destructuring
How can you tell the difference between destructuring and creating Object/Array literals?
variable name at start(left)= creating literals
variable name at end(right) = destructuring literals
es6-arrow-functions
What is the syntax for defining an arrow function?
optional variable declaration, assignment operator, optional params (if 0 param then no parenthesis, if 1 param optional parenthesis, more than 1 then parentheses is needed), arrow, then a single expression or a code block
es6-arrow-functions
When an arrow function’s body is left without curly braces, what changes in its functionality?
it returns (implicitly) from the function
If using expression like ‘x + y’, then ‘return’ keyword/statement not needed.
Note: expression has a result value. statement doesn’t have a result, it is more of a command
If using curly braces then it needs ‘return’ keyword/statement.
Note: in react (expression-based) if put statement into where expression should be then it will error
es6-arrow-functions
How is the value of ‘this’ determined within an arrow function?
better to look at it as when is ‘this’ determined.
Arrow functions captures the ‘this’ value of the enclosing context rather than making its own ‘this’ (similar to how scope works)
arrow functions: ‘this’ is defined at function definition
traditional functions: ‘this’ is defined at function call
Note: in the example exercise, the setTimeout functions are being defined multiple times when the function runs (‘this’ is the jokester object with the arrow functions in setTimeout)
Note2: to bypass ‘this’ being window object when undefined (global ‘this’) then you assign ‘this’ to a variable. For example: ‘var realThis = this’
Note3: if you made the functions of the properties of jokester using ‘traditional ES5 functions’ then it would grab the global ‘this’ object because ‘this’ will be defined at function call
Note4: function names AND values are hoisted to the top, while var names are hoisted, but their values aren’t evaluated till JavaScript reaches their code line. Tim’s tip: Create functions and vars where you need them, then you can move the functions/variables around (like using utility functions at the bottom)
command-line-basics
What is a CLI?
Stands for command-line interface.
It processes commands to a computer program in the form of lines of text
command-line-basics
What is a GUI?
Stands for graphical user interface.
It is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation. Example of GUI text editor is VS Code
command-line-basics
Give at least one use case for each of the commands listed in this exercise.
- man - cat - ls - pwd - echo - touch - mkdir - mv - rm - cp
man: review what a command does (manual)
cat: print out contents of a file into terminal or combine contents of a file.
ls: list files in a current directory (can go to other directories if using path)
pwd: print current working directory
echo: display a line of text (string) into terminal, which can be added to a new file
touch: create a new file in current directory (if you use path then you can create the file in another directory)
mkdir: create a new directory
mv: move or rename a file (renaming something also moves it)
rm: remove/delete a file or directory (there is no undo and it doesn’t go into the trash)
cp: copy a file, which you can rename in the same line
command-line-basics
What are the three virtues of a great programmer?
- Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don’t have to answer so many questions about it.
- Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to.
- Hubris: The quality that makes you write (and maintain) programs that other people won’t want to say bad things about.
node-intro
What is Node.js?
A back-end JavaScript runtime environment (program) that operates on the Chrome V8 engine and executes JavaScript code outside of a browser.
node-intro
What can Node.js be used for?
Node.js can be used to execute JavaScript outside of the web browser. Develop command-line applications, server applications, and other back-ends.
node-intro
What is a REPL?
Stands for read, evaluate, print, and loop (loop because it waits for next input). It’s a computer environment where you can write code and execute code.
node-intro
When was Node.js created?
Node.js was created on May 27, 2009
node-intro
What back end languages have you heard of?
JavaScript (node.js), ruby, python, php, c# (.NET), perl, typescript, assembly, go, sql (for programming databases), haskell (only has functions (has to return something) and data, Tim said it changed the way he wrote JavaScript in a good way)
Scripting Languages (often interpreted): ruby, python, php, javascript, perl
Compiled Languages (analyzes source code then makes new set of code): c, c++, go, haskell, c# (.NET), f#, java, assembly (maybe compiled??), typescript
sql on it’s own