ES6 Flashcards

1
Q

ES6-CONST-LET

What is a code block? What are some examples of a code block?

A

JavaScript statements can be grouped together in code blocks, inside curly brackets {…}.
The purpose of code blocks is to define statements to be executed together.
Examples: function code block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

ES6-CONST-LET

What does block scope mean?

A

A block scoped variable means that the variable defined within a block will not be accessible from outside the block. A block can reside inside a function, and a block scoped variable will not be available outside the block even if the block is inside a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

ES6-CONST-LET

What is the scope of a variable declared with const or let?

A

Block scope

The let keyword is similar to the var keyword, except that these variables are blocked-scope.
(are not initialized to any value, and are not attached to the global object)

const keyword are blocked-scope and cannot be redeclared.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ES6-CONST-LET

What is the difference between let and const?

A

const cannot be reassigned

both are block-scoped variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

ES6-CONST-LET

Why is it possible to .push() a new value into a const variable that points to an Array?

A

The const keyword ensures that the variable it creates is read-only. However, it doesn’t mean that the actual value to which the const variable reference is immutable.

Cannot reassign the array to another array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ES6-CONST-LET

How should you decide on which type of declaration to use?

A
var = global scope
let = block scope but use if need to reassign
const = block scope if read only and no reassignment
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

ES6-TEMPLATE-LITERALS

What is the syntax for writing a template literal?

A
Use the backtick to create a string literal for string interpolation
variable declaration (let, const, var) = `string ${'Fred'.toUpperCase()} string`;
console.log // string FRED string

(JavaScript string interpolation is the process of embedding an expression into part of a string).

${ ‘variable’}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

ES6-TEMPLATE-LITERALS

What is “string interpolation”?

A

String formatting: the ability to substitute part of the string for the values of variables or expressions. This feature is also called string interpolation.

${ variable }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is destructuring, conceptually?

A

Destructuring broadly means extracting data from arrays or objects.
Taking the values and assigning them into new variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A

const { propKey1: propAlias, propKey2 } = someObject;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A

const [first, second, third, fourth] = theArray

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
A

create an object/array
keyword = [] / {}

destructuring an object/array
keyword [ variables ] = object/array

where the brackets/braces are located (left or right side)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the syntax for defining an arrow function?

A

(param1, param2) => {
return;
}

param => exp;

( ) => exp;
_______________________________________________________________
const functionName = parameter => expression

or const functionName = (param1, param2) => param1 + param2

or const functionName = (param1, param2) => ( {param1:param2} )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

function body gets evaluated as an expression

it has an implicit return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How is the value of this determined within an arrow function?

A

arrow functions have a lexical scope (using global variables) so the value of ‘this’ is determined by the surrounding scope.

takes the this from the enclosing function (parent)
‘this’ is determined when an arrow function is defined (definition time)

i.e. either window if it’s a global scope or local variable if arrow function is wrapped in a regular function

tim : arrow function = ‘this’ is defined at definition time
regular function = ‘this’ is defined at call time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

COMMAND-LINE-BASICS

What is a CLI?

A

Command-line interface (CLI)

A command-line interpreter or command-line processor uses a command-line interface (CLI) 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

COMMAND-LINE-BASICS

What is a GUI?

A

Graphical User Interface (GUI)

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.
GUIs were introduced in reaction to the perceived steep learning curve of CLIs (command-line interfaces), which require commands to be typed on a computer keyboard.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* man

A

man - an interface to the system reference manuals

Ex. man cat 
//
name 
synopsis
description
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* cat

A

cat - concatenate files and print on the standard output

Example: cat laziness.txt
// shows the text content on the terminal ~
1. Laziness: The quality that makes you go to great effort to reduce overall energy expenditure…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* ls

A

ls - list directory contents

Example: ls pokemon/
//
bulbasaur
charmander
squirtle
21
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* pwd

A

pwd - print name of current/working directory

Example: pwd
//
/workspaces/c0622-code-solutions/command-line-basics

22
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* echo

A

echo - display a line of text

Example: echo ‘Hello, World!’
//
Hello, World!

echo 'Hello, World!' > hello.txt
// creates a new file with 'Hello, World!'
23
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* touch

A

touch - change file timestamps

Example: touch tag-youre-it.txt
// creates a new file named tag-youre-it
touch snoot/boop.txt
// creates a new file named boop.txt inside the snoot directory
24
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* mkdir

A

mkdir - make directories

Example: mkdir parent
// makes a parent directory (folder)
mkdir -p parent/child/grandchild
// creates nested directories (folders)
25
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* mv

A

mv - move (rename) files

Example: mv pokiemans pokemon
// renames pokiemans to pokemon
26
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* rm

A

rm - remove files or directories

Example: rm lol.txt
// deletes lol.txt file
27
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* cp

A

cp - copy files and directories

Example: cp and-then.txt no-and-then.txt
// makes a copy of and-then.txt and creates a new file names no-and-then.txt with the same contents
28
Q

COMMAND-LINE-BASICS
Give at least one use case for each of the commands listed in this exercise.
* history

A

man history - shows description of history of GNU

history — shows all recent command line commands to terminal

history > command-history.txt — creates a new file containing command line history

29
Q

COMMAND-LINE-BASICS

How to go to parent directory?

A

cd ..

30
Q

COMMAND-LINE-BASICS

Terminal Within Exercise’s Directory

A

cd name-of-exercise

31
Q

COMMAND-LINE-BASICS

What are the three virtues of a great programmer?

A
  1. 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.
  2. 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.
  3. Hubris: The quality that makes you write (and maintain) programs that other people won’t want to say bad things about.
32
Q

NODE-INTRO

What is Node.js?

A

Node.js is a program that allows JavaScript to be run outside of a web browser.

33
Q

NODE-INTRO

What can Node.js be used for?

A

It is commonly used to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.

34
Q

NODE-INTRO

What is a REPL?

A

Read-eval-print loop (REPL)

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; a program written in a REPL environment is executed piecewise.

35
Q

NODE-INTRO

When was Node.js created?

A

May 27, 2009

Invented by Ryan Dahl, Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on a JavaScript Engine and executes JavaScript code outside a web browser, which was designed to build scalable network applications.

36
Q

NODE-INTRO

What back end languages have you heard of?

A

JAVA, SQL, RUBY PHP
C++, C#, PYTHON, FORTAN, C,
GOLANG, JAVASCRIPT, SWIFT, PERL, KOTLIN,

// Scripting Languages 
// These are interpreted on-the-fly
- python
- ruby (jit: just-in-time compilation)
- php
- javascript (jit)
-perl
- elixir
// Memory Managed Languages
// These languages are compiled ahead of time
// garbage collection
- java / kotlin
- c#
- golang
- haskell
- julia
- f#
- fortan
// Manual Memory Management
// Ahead of Time Compiled
// low-level
- c++
- c
-swift
- rust
- d 
- zig
  • sql - for databases
37
Q

NODE-PROCESS-ARGV

What is the process object in a Node.js program?

A

The process object is a global that provides information about, and control over, the current Node.js process.

The process object in Node. js is a global object that can be accessed inside any module without requiring it.

38
Q

NODE-PROCESS-ARGV

How do you access the process object in a Node.js program?

A

its global, just like window

so you just grab it

39
Q

NODE-PROCESS-ARGV

What is the data type of process.argv in Node.js?

A

an array of strings

40
Q

NODE-MODULE-SYSTEM

What is a JavaScript module?

A

In JavaScript, a “module” is a single .js file. Node.js supports modules using a system heavily influenced by CommonJS. Most non-trivial Node.js programs are made of many, many modules. Authors of Node.js programs strive to separate their code into modules that each provide a small chunk of functionality. The program as a whole is the result of all of these modules working together in concert.

41
Q

NODE-MODULE-SYSTEM

What values are passed into a Node.js module’s local scope?

A

The five parameters — exports , require , module , __filename , __dirname are available inside each module in Node. Though these parameters are global to the code within a module yet they are local to the module

42
Q

NODE-MODULE-SYSTEM

Give two examples of truly global variables in a Node.js program.

A

console and process

43
Q

THE-EVENT-LOOP

What is the JavaScript Event Loop?

A

JavaScript has a runtime model based on an event loop, which is responsible for executing the code, collecting and processing events, and executing queued sub-tasks.

44
Q

THE-EVENT-LOOP

What is different between ‘blocking’ and ‘non-blocking’ with respect to how code is executed?

A

Blocking is when the execution of additional JavaScript in the Node.js process must wait until a non-JavaScript operation completes.
Synchronous

Non-blocking
Asynchronous

45
Q
A

Special kind of file

list items and directories

46
Q
A

path to a file from where you are

47
Q
A

starts from the root of the file system

48
Q
A

the fs module