senior side Flashcards
What is a code block? What are some examples of a code block?
A code block is code within the curly braces
some examples would be function defenitions and if statements
What does block scope mean?
Block scope means that a variable is only available within the code block it was defined in
What is the scope of a variable declared with const or let?
Block scope
What is the difference between let and const?
let values are mutable and const variables are not
Why is it possible to .push() a new value into a const variable that points to an Array?
we are not changing the id of the array
How should you decide on which type of declaration to use?
let is anything you want to change and const remains the same and cant be changed
What is the syntax for writing template literals in ?
backticks (
)
${}
What is “string interpolation”?
String formatting: the ability to substitute part of the string for the values of variables or expressions. This feature is also called string interpolation.
inside a string we replace the value with the variable
What is destructuring, conceptually?
provides an alternative way to assign properties of an object to variables:
getting data from an object and storing in into variable
What is the syntax for Object destructuring?
const { firstName: fname, lastName: lname } = person;
What is the syntax for Array destructuring?
let [x, y, z] = getScores
variable name and the order their at is its index
How can you tell the difference between destructuring and creating Object/Array literals?
destructuing: brackets are on left hand side
creating: they are on the right
any chance you get to use destructuring then use it but dont have to use it all the time
what is the syntax for defining an arrow function
param => expression
var keyword function name = parameter => expression
let add = (x, y) => x + y;
When an arrow function’s body is left without curly braces, what changes in its functionality?
Without braces, you can only use an single-line expression in the body of the arrow function.
implicitly returns a value
How is the value of this determined within an arrow function?
//An arrow function captures the ‘this’ value of its enclosing context.//
takes value of this from the function it was defined from
What is a CLI?
Command line Interface
to receive commands from a user in the form of lines of text
This provides a means of setting parameters for the environment, invoking executables and providing information to them as to what actions they are to perform
What is GUI
graphical user interface
is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, instead of text-based UIs, typed command labels or text navigation.
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 man
to get the manual for the command we run
//
////
cat is used to read a file sequentially and print it to the standard output
concatenate files and print on the standard output
cat laziness.txt
//
ls -a -F
ls -a lists all contents in the working directory, including hidden files and directories
ls" on its own lists all files in the current directory except for hidden files. "ls *. // pwd to check and see the working directory you are on // echo "Hello World!" prints out text you can direct to new file with > // touch tag-your-it.txt touch creates the blank file // mkdir to make a directory // mv to move and rename files // rm to delte a file or directory // cp to copy a file or whole directory into a new name (-and-no-text >no-and-then-text) //
What are the three virtues of a great programmer?
laziness impatience hubris
cat command will print the file you give it after running cat name-of-file
pwd prints the working directory
cat laziness.txt impatience.txt hubris.txt > three-virtues.txt will create a new file named three-virtues.txt and store laziness, impatience and hubris
echo runs the string you give it right away
echo ‘Hello World!” > hello.txt will make a new file names hello.txt
mkdir command will make a directory
mv will change the name of a file
example: mv pokiemans pokemon
rm will delete a file or directort (BE CAREFUL)
cp will copy a file and give it another name if you would lie
example: cp no-and-then.txt and-then.txt
use the history command to check all the commands I ran previously
///
$ cat oceans.txt > continents.txt
> takes the standard output of the command on the left and redirects it to the file on the right.
///
ls -a lists all contents in the working directory, including hidden files and directories
///
mkdir
$ mkdir media
mkdir takes in a directory name as an argument, and then creates a new directory in the current working directory. Here we used mkdir to create a new directory named media/.
///
rm
$ rm waterboy.txt
rm deletes files. Here we remove the file waterboy.txt from the file system.
///
rm -r
$ rm -r comedy
rm -r deletes a directory and all of its child directories.
touch
$ touch data.txt
touch creates a new file inside the working directory. It takes in a file name as an argument, and then creates a new empty file in the current working directory. Here we used touch to create a new file named keyboard.txt inside the 2014/dec/ directory.
If the file exists, touch is used to update the modification time of the file
Use the ls command to list the contents of your current working directory. Try it again with the -a and -F options.
Use the ls command to list the contents of the lfz-staff/ directory. Try it again with the -a and -F options.
Use the pwd command to write your current working directory to a new file named i-was-here.txt like this:
pwd > i-was-here.txt
Use the echo command to print the string ‘Hello, World!’ to the terminal.
Use the echo command to write the string ‘Hello, World!’ to a new file named hello.txt like this:
echo ‘Hello, World!’ > hello.txt
Use the touch command to create a new file named tag-youre-it.txt.
Use the touch command to create a new file named boop.txt inside of the snoot/ directory (i.e. snoot/boop.txt).
Use the ls command to list the contents of the snoot/ directory.
mkdir
Use the ls command to list the contents of the lfz-staff/ directory and write the results to a new file at lfz-staff/contents.txt like this:
ls -aF lfz-staff > lfz-staff/contents.txt
main takeaway is it gets this from the parent scope
syntax of arrow function
have to be passing it as a callback function or define it in a variable
const add1 = (x,y) => { return x + y }
const result1 =add1(12,56)
Learned so far on senior side
const/let
template literals
arrow functions
destructuring
What is node.js?
Environment to run JavaScript code outside of the browser