Senior Side Week 1 Flashcards
What is a code block? What are some examples of a code block?
A code block is when their are lines of code that is grouped together. Typically code blocks are grouped by curly braces. Some example of code blocks are if statements, for loops, while, and do while loops
What does block scope mean?
Block scope means that any variable or function is only visible within that block of code and not outside of it
What is the scope of a variable declared with const or let?
They have a block-level scope.
What is the difference between let and const?
Const variable cannot change while let variable can.
Why is it possible to .push() a new value into a const variable that points to an Array?
The const keyword only applies to the variable reference (i.e., the memory address that the variable points to), not the value itself.
How should you decide on which type of declaration to use?
If the variable needs to be mutable later on, use let. If the variable doesn’t change at all, then use const. If you don’t know if it is going to change just use const and change it back later.
What is the syntax for writing a template literal?
The syntax is backticks (`)
What is “string interpolation”?
The syntax used is ${expression}. It is when you can insert the value of the expression within the string. Makes it easier to read the code.
What is destructuring, conceptually?
It makes it the code more concise and easier to readable. It allows us to assign elements in array or objects to variables so that it is easier to grab
What is the syntax for Object destructuring?
let { firstName: fname, lastName: lname } = person;
//this is for renaming the variable
or
you can keep it like this
let { firstName, lastName } = person;
//this doesn’t rename it
What is the syntax for Array destructuring?
Instead of brackets that are used in objects, we use square brackets with a variable name for each element for each index.
let [x, y, z] = array;
How can you tell the difference between destructuring and creating Object/Array literals?
We can tell by which side the object and array is in the expression.
What is the syntax for defining an arrow function?
=>
When an arrow function’s body is left without curly braces, what changes in its functionality?
The arrow function will automatically return the expression. If the expression is more than one statement then you you need curly braces and a return syntax
How is the value of this determined within an arrow function?
The “this” is determined by the scope in which the arrow function is defined and not where it is called
What is a CLI?
CLI stands for command-line interfaces. Uses the command-line interface to receive commands from a user in the form of lines of text.
What is a GUI?
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, instead of text-based UIs, typed command labels or text navigation. Typically used by consumers and not developers.
man
Definition: an interface to the system manuals
Description: man is the system’s manual pager. Each page argument given to man is normally the name of a program, utility or function. The manual page associated with each of these arguments is then found and displayed. A section, if provided, will direct man to look only in that section of the
manual. The default action is to search in all of the available sections following a pre-defined order (see DEFAULTS), and to show only the first page found, even if page exists in several sections.
Use Case: Used to find commands if you don’t know one
cat
Definition: concatenate files and print on the standard output
Description: Concatenate files to standard output
Use Case: to know what is in the file
ls
Definition: list directory contents
Description: List information about the FILEs
Use Case: To see what files are in the directory
pwd
Definition: print name of current/working directory
Description: Print the full filename of the current working directory
Use Case: to know the full path
echo
Definition: display a line of text
Description: the String(s) to standard output
Use Case: not really
touch
Definition: change file timestamps
Description: Update the access and modification times of each File to the current time.
A file argument that does not exist is created empty, unless -c or -h is supplied.
A file argument string of - is handled specially and causes touch to change the times of the file associated with standard output.
Use Case: makes a timestamp for a file and it can create a new file
mkdir
Definition: make directories
Description: Create the directory(ies) if they do not already exist.
Use Case: When you want to create a folder
mv
Definition: move (rename) files
Description: Rename source to dest, or move source(s) to directory
Use Case: to rename files
rm
Definition: remove files or directories
Description: removes each specified file. by default, it does not remove directories.
Use Case: To delete files
cp
Definition: copy files and directories
Description: Copy source to dest, or multiple source(s) to directory
Use Case: to copy files
What are the three virtues of a great programmer?
laziness, hubris, impatience
What are the 3 components of a fullstack Web architecture?
1) Presentation tier
2) Logic tier
3) Data tier
What is Node.js?
Allows developers to run JavaScript code outside of a web browser. It is commonly used to build backends for Web applications, command-line programs, or any kind of automation that developers wish to perform.
What can Node.js be used for?
It can be used for the server-side of applications and backends for Web applications
What is a REPL?
It stands for read-eval-print loop. It is a programming language feature that allows developers to interactively execute code and see the results immediately. It can only take a single user input.
When was Node.js created?
2009
What backend languages have you heard of?
Python, Ruby, Java, PHP
What is computer process?
A computer process refers to a series of task or operations that a computer or computer program performs to complete a specific task
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
397
Why should a full stack Web developer know that computer processes exist?
Helps the developers create efficient, scalable, and optimized for performance
What is the ‘process’ object in a Node.js program?
The ‘process’ object is a ‘global’ that provides information about, and control over, the current Node.js process.
How do you access the ‘process’ object in a Node.js program?
Using the global variable ‘process’. This object provides the information about and control over the current Node.js process running the program.
What is the data type of ‘process.argv’ in Node.js?
An array containing the command line arguments passed when the Node.js process was launched.
How do you access the command line arguments in a Node.js program?
Use process.argv
What is a JavaScript module?
A module is a single .js file. Every module is basically a file.
What are the advantages of modular programming?
Reusability, maintainability, scalability, collaboration, organized, testing
In JavaScript, how do you make a function in a module available to other modules?
Using export declaration.
You don’t need to use default. There is only one thing that can export by default.
If you don’t have default you need the curly braces.
In JavaScript, how do you use a function from another module?
Using import declaration
What is the JavaScript Event Loop?
The event loop’s job is to look at the stack and the task.queue. If the stack is empty it takes the first thing on the queue and pushes it on to the stack. It has to wait till the stack is cleared for the event loop to kick in
What is the different between “blocking” and “non-blocking” with respect to how code is executed?
Blocking: Synchronous. Slow. Waits till a code finishes running before it goes to the next. This can halt and processes in the browser till it finishes a whichever line of code that comes first,.
Non-blocking: Asynchronous. Fast.
What are the three states a Promise can be in?
Pending: initial state, neither fulfilled nor rejected
Fulfilled: meaning that the operation was completed successfully
Rejected: meaning that the operation failed
How do you handle the fulfillment of a Promise?
using ‘.then’
How do you handle the rejection of a Promise?
using ‘.catch’
What does ‘Array.filter’ do?
It filters down the array based on if the function given passes the requirements. It doesn’t modify the array. so make sure to assign it to a variable
What should the callback function return?
It should return a boolean value.
It should return a portion of the given array, filtered down to just the elements from the given array that passes the test implemented by the provided function.
What is Array.filter useful for?
It’s useful for finding the elements that you only want to search for.
What does ‘Array.map’ do?
Creates a new array with the results of calling a provided function on every element in the calling array.
What should the callback function return?
It returns a new array with each element being the result of the callback function.
What is ‘Array.map’ useful for?
It is useful if you need to manipulate all the elements in the array
What does ‘Array.reduce’ do?
Reduce an array to a single value by iterating over its elements and applying a function that accumulates the results.
What action should the callback function perform?
The callback function that is passed as the first argument to Array.reduce() should perform the action that you want to apply to each element of the array, and accumulate the result into the accumulator.
It accumulates each element in order.
What should the callback function return?
The value that results from running the ‘reducer’ callback function to completion over the entire array. Typically, the accumulated value.
What is Array.reduce useful for?
To sum up the entire array, finding the max and min values of an array, flatten nested arrays, grouping objects by specific properties
What is a directory?
A container that stores files and other directories. Known as a folder.
What is a relative file path?
A relative file is a file path that is relative to the current working directory or location of the file being accessed.
What is an absolute file path?
A file path that specifies the complete path to a file or directory on a file system. Absolute always starts at the root.
What module does Node.js include for manipulating the file system?
The ‘fs’ (file system) module for manipulating the file system.
The “fs” module provides methods for working with files, directories, and file system operations like reading and writing files, creating and deleting directories, renaming and moving files, and other file-related tasks.
What method is available in the node:fs module for reading data from a file?
fs.readFile
What method is available in the ‘node:fs’ module for writing data to a file?
writeFile
Are file operations using the ‘fs’ module synchronous or asynchronous?
Asynchronous