BackEnd Flashcards
What is a code block? What are some examples of a code block?
- lexical structure of source code that are grouped together. Code Blocks consist of one or more declarations and statements. (lexiscope refers to setting the scope, or range of functionality, of a variable so that it may be called (referenced) from within the block of code in which it is defined.)
- In JavaScript, code blocks are denoted by curly braces { }.
- For example, if else, for, do while, while and so on.
What does block scope mean?
Block scope means the variable definition is only valid within the block of code that it was declared in.
What is the scope of a variable declared with const or let?
const and let variables are Block-Scoped.
What is the difference between let and const?
Let can be reassigned and Const cannot.
Why is it possible to .push() a new value into a const variable that points to an Array?
It is possible to .push() to a new value into a const variable, because it is adding to the array instead of reassigning the variable.
The values in the array are mutable.
How should you decide on which type of declaration to use?
If the variable does not needed to be reassigned, then use const
What is the syntax for writing a template literal?
- put it inside backticks (``)
- ${ } holds the expressions and variables
example:
let name = ‘sharon’;
let age = 26;
phrase = hi my name is ${ name } and I am ${ age } years old
;
What is “string interpolation”?
String formatting: the ability to substitute part of the string for the values of variables or expressions.
What is restructuring conceptually?
Taking out part of an object and assigning it to new variables
What is the syntax for Object destructuring?
const { title, author, libraryID } = book1
What is the syntax for Array destructuring?
const [ book3, book4, book5 ] = getBooks()
How can you tell the difference between destructuring and creating Object/Array literals
the side of the assignment operator that the object or array is on.
creating object : def is right side of the equal sign
restructuring: { } and property name is on the left side of the =
What is the syntax for defining an arrow function?
functionName = parameter => {
code block
}
functionName = () => { }
() not needed with one parameter
() are needed with no parameter
{} needed for more than one line of code
When an arrow function’s body is left without curly braces, what changes in its functionality?
You don’t get a return statement.
How is the value of this determined within an arrow function?
this is defined at definition time for arrow functions. In other words, THIS is defined within the same lexiscope or parentscope.
For other functions, this is determined at call time
What is Node.js?
Node.js is a program that allows JavaScript to be run outside of a web browser.
What can Node.js be used for?
Building back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.
What is a REPL?
A read–eval–print loop (REPL), also termed an interactive top-level or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user; a program written in a REPL environment is executed piecewise.
Chrome Dev Tools Console is one example.
This is more like a playground for testing things.
When was Node.js created?
May 27, 2009
What back end languages have you heard of?
Node, Python, PHP, Ruby
What is the process object in a Node.js program?
• The process object is a global
• that global informs about and controls the current Node.js process.
• As a global, it is always available to Node.js applications without using require().
• It can also be explicitly accessed using require():
const process = require(‘process’);
How do you access the process object in a Node.js program?
Just type process, it is always available. Treat it like any other object.
It is a global so you can access it anywhere.
What is the data type of process.argv in Node.js?
Array
What is a JavaScript module?
Module in Node.js is a functionality organized in single or multiple JavaScript files that are reused.