Section 2 Flashcards
(139 cards)
What is a code block? What are some examples of a code block?
- denoted by curbraces
- if/else, for, do while, while, try, catch, etc
What does block scope mean?
- inside the code block
- things that happen inside the curbraces
What is the scope of a variable declared with const or let?
block-scope
- var uses global (the window global object)
- var is FUNCTION scoped
- let is not attached to the global object
- let is BLOCK-SCOPED, not initialized to any value, and not attached to the global object.
What is the difference between let and const?
- let is mutable, can be reassigned, and doesn’t have to be initialized
- const is read-only/constant, can’t be reassigned, but can be modified, is not immutable, must have initialization
- by convention, the constant identifiers are in uppercase.
const CONSTANT_NAME = value;
Why is it possible to .push() a new value into a const variable that points to an Array?
- bc we’re not reassigning a block-scope, we’re just modifying the array held by the const variable
- const’s values can change/be mutated, but it cannot be reassigned to a dif block-scope value
How should you decide on which type of declaration to use?
is the whole variable being reassigned (let), or are just the values inside the variable changing (const)
arrays & objects, always CONST
What is the syntax for writing a template literal?
backticks: this is a template literal
What is “string interpolation”?
imbedding variables & expressions in a string and JS automatically replacing them with their values
it looks like ${variable_name} this
__code read: ___
const bio = My name is ${firstName} ${lastName} and I am ${age} years old.
;
there is a template literal string with the substitutions firstName, lastName, and age, being assigned to the const bio
What is destructuring, conceptually?
- a way to assign the properties of an object to individual variables
- to get values from an object
What is the syntax for Object destructuring?
let { propertyName: variableName, propertyName: variableName } = sourceObject;
so ‘sourceObject.propertyName’ is now ‘variableName’ for ease of use
Object destructuring assigns the properties of an object to variables with the same names by default.
What is the syntax for Array destructuring?
let [var, for, each, index] = scrArray/srcFunc()
How can you tell the difference between destructuring and creating Object/Array literals?
assignment is inverted
creating, on the right
destructuring, on the left
code read:
const { title, author, libraryID } = book1;
const { title: eek, author: barba, libraryID: durkle } = book2;
the const title, author, libraryID are being destructured from book1
the const title is being aliased with eek … being destructured from boook2
What is the syntax for defining an arrow function?
parameter list, arrow, codeblock
let funcName = (parameter) => { return expression; };
When an arrow function’s body is left without curly braces, what changes in its functionality?
- it will return automatically
- implicit/implied return = withOUT curbraces
- explicit return = WITH cubraces
How is the value of THIS determined within an arrow function?
- from the enclosing lexical scope. so you cannot use a new this in an arrow function, unless you:
- assign the this to a variable, then use that variable in your arrow function
- this in an arrow func captures this’s value from the enclosing context instead of creating its own
What is a CLI?
command line interface
What is a GUI?
graphical user interface
Give at least one use case for each of the commands listed in this exercise.
man – interface to the online reference manuals
cat – concat files & print to standard output, but rly for viewing file contents
_cat filename -quickly see the contents of a file
ls – list directories
pwd – print working directory
echo – display a line of text
touch – change file timestamps, but rly for creating empty files
_touch empty-file.txt -create an epmty file
mkdir – make directories
mv – move (rename) files
rm – remove files/directories
cp – copy files/directories
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.
What is Node.js?
- a js environment outside of a browser
- can be used to build a server
a program that allows JavaScript to be run outside of a web browser, especially for talking/building to backend/servers/etc as a foundation for a web application
What can Node.js be used for?
building servers or backends for web applications
What is a REPL?
Read–eval–print loop
A read–eval–print loop (REPL), also termed an interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user.