Week 8 Flashcards
What is a code block? What are some examples of a code block?
A set of code within curly braces.
Examples: function code block, loop code block
What does block scope mean?
It means that the variable that was defined within a block will not be accessible from outside the block aka outside of the curly braces
What is the scope of a variable declared with const or let?
block scope
What’s the difference between let and const?
Const are variables that cannot be reassigned
You also need to initialize the value declared by the const keyword (ex: cannot just say const red;
Why is it possible to .push() a new value into a const variable that points to an array?
The value within the array is mutable
You cannot change the value of a constant through reassignment but you can update the value of the properties or items
How should you decide on which type of declaration to use?
If the variable is not going to be reassigned, use const
if it is going to be reassigned, use let
What is the syntax for writing a template literal?
Wrap the text in backticks ` and include any expressions inside of the template literal with ${}
example:
const fruit = ‘apple’
const item = ‘pen’
const applepen = ${fruit}${item}
What is string interpolation?
technique that allows you to insert variable or expression values into a strings
const fruit = ‘apple’
const item = ‘pen’
const applepen = ${fruit}${item}
What is the syntax for defining an arrow function?
( parameter1, paremeter2, etc..) => { }
if it has no parameters, parenthesis are mandatory. If there is 1 parameter, parenthesis are not mandatory. If there are multiple, it is mandatory.
If there is a simple expression, curly braces are not needed. If there are multiple statements, it requires curly braces
When an arrow function’s body is left without curly braces, what changes in its functionality?
Without curly braces, the arrow function has an implicit return (returns something even without the return keyword)
How is the value of this determined within an arrow function?
The value of this is determined by surrounding scope/surrounding code block. aka it doesn’t have its own value and will look outward. aka the value of this will be determined at definition time
What is CLI?
Command line interface: receives commands from a user in the form of lines of text
What is GUI?
Graphical user interface: form of user interface that allows users to interact through graphical icons and audio indicator instead of text-based UIs
Give one use case for the command: man
Documentation for commands
Give one use case for the command: cat
concatenate files and print on the standard output
Give one use case for the command: ls
lists directory content and sorts alphabetically if none is specified
Give one use case for the command: pwd
prints the name of the current working directory aka where you’re currently at
Give one use case for the command: echo
displays a line of text aka console.log for the terminal
Give one use case for the command: touch
change file timestamps / update the access and modification times of each file to the current time; you can also use this to create files
Give one use case for the command: mkdir
make directories (if they don’t already exist)
Give one use case for the command: mv
move or rename files
Give one use case for the command: rm
removes files or directories (done immediately and permanently)
Give one use case for the command: cp
copies files and directories
What is Node.js?
Program that allows JS to be run outside of a web browser
What can Node.js be used for?
Build backends for web apps, command-line programs and any kind of automation