Express Flashcards

1
Q

NODEJS What is it and what is its function?

A

Node.js is a runtime environment (a program that runs other programs), a platform used to execute JavaScript applications outside the browser.

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

What does JSON mean?

A

JSON is (JavaScript Object Notation) this helps the web-server communicate with clients

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

What are some of the advantages of using NODE.js server-side code?

A

1) ..JavaScript on the server: use the same programming language and paradigm for both client and server. This minimizes context switching and makes it easy to share code between the client and the server.
2) ..Single-threaded: removes the complexity involved in handling multiple threads.
3) ..Asynchronous: can take full advantage of the processor it’s running on. This matters because the node process will be running on a single CPU.
4) ..Npm repository: access the largest ecosystem of useful libraries (most of them free to use) in the form of npm modules.

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

What are some of the Disadvantages of using NODE.js server-side code?

A

1) ..JavaScript on the server: we lose the ability to use the right tool (language) for the job.
2) ..single-threaded: can’t take advantage of servers with multiple cores/processors.
3) ..asynchronous: it is harder to learn for developers that have only worked with languages that default to synchronous operations that block the execution thread.
4) ..npm repository: too many packages that do the same thing makes it harder to choose one and, in some cases, may introduce vulnerabilities into our code.

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

How would you write a simple web server with Node.js?

A

1) .. Use Node’s HTTP module to abstract away complex network-related operations.
2) .. Write the single request handler function that will handle all requests to the server.

The request handler is a function that takes the request coming from the client and produces the response. The function takes two arguments: 1) an object representing the request and 2) an object representing the response.

This process works, but the resulting code is verbose even for the simplest of servers. Also, note that when using only Node.js to build a server, we use a single request handler function for all requests.

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

What is

User Interface?

A

Is the combination of HTML(“Hypertext Markup Language”) & CSS(“Styles the HTML”)

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

What is GIT and how do you use it?

A

Git is a distributed version control system

Git monitors and controls code changes made during development across several people and teams.

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

What is HTML?

A

HTML is one of the languages we use for web development.

HTML is what we call a “markup language” (as opposed to a “programming” language like JavaScript or Python).

A markup language means that it is specifically designed to display data in a graphical form (rather than execute tasks).

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

What are some HTML Elements?

A

HTML elements are like boxes of content on our web page. Different types of content can be in these boxes for example <h1></h1>

h1 = header for titles or most important content
can only be used once in a coding program.

<h1> Lambda School is Awesome </h1>

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

What are tags?

A

If we wanted to tag the sentence above as an essential header (the biggest text by default), we’d use the <h1> and </h1> beginning and end tags, as shown below.
Tags identify elements in your code each element has text

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

So What are Divs, Headers, Paragraphs, and Spans?

A

These are display elements

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

How would you display a Paragraph in HTML?

A
<p>
The p ("paragraph") element. This element is meant for holding text. By default, it will render text to the screen on a new line.

</p><p>Here is a paragraph!</p>

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

What is a div?

A

<div>
The div element is a generic container. It is used primarily for grouping other HTML elements together. It is invisible by default but can be used to position or style a group of elements. Div isn't super helpful in plain HTML but will become powerful when we "stack" HTML with JavaScript and CSS.
<div> is a block-level element, meaning it will take up a full line.
<div>
<p>This paragraph is about grapefruits.</p>
<p>This paragraph is also about grapefruits! I guess it's related to the paragraph above.</p></div></div></div>

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

What is a span element?

A

<p>This paragraph contains a <span>very important phrase</span> that should be styled in some way.</p>

<span>
The span element is a generic text container. It does not create a new line as the p element does. This element is invisible by default but can style words or phrases within a larger body of text.
Unlike <div>, <span> operates inline and therefore doesn’t take up its own line.
</span></div></span>

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

What are h tags?

A

<h1>-</h1>

<h6>
These are heading tags. They are intended to be used as a way to present the subject matter of the page. 1 is the most important, and 6 is the least important. By default, 1 will be the largest, 2 will be the next largest, etc.
Avoid using heading tags to resize text. Headings use size to indicate their relative importance, but CSS is preferred for general-purpose resizing.
You should only use one </h6>

<h1> per page. Using more than one will not result in an error, but using only one is seen as a best practice. It makes logical sense — </h1>

<h1> is the most important heading and tells you the purpose of the overall page. You wouldn't have a book with more than one title or a movie with more than one name! Having a single top-level title is also arguably better for screen reader users and SEO.
</h1>

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

What are Semantic and Non-semantic elements in HTML?

A

We use the word semantic to describe tags with meaning.

Some examples of semantic tags include:

<h1></h1>

<p></p>

Nonsemantic tags
<div>
<span> </span></div>

17
Q

What are variables in JS?

A

Variables are a way to store, change and use code

18
Q

Variable Syntax

A
var name = "brit";
let name = "brit";
const name = "brit"
19
Q

var

A

var can be re-assigned and changed but causes buggy issues

var is a generic variable KEYWORD.

Variables created with (var) can be changed without causing errors but using var to much may cause buggy code

var firstName = "Alice";
firstName = "Bob";
once you declare the variable you can change it without having to declare it again like above code.
20
Q

CONST

A

const CANNOT be re-assigned nor changed

A const variable is a variable that cannot be changed later in the code. It’s short for “constant”.

const firstName = 'Alice'
firstName = 'Bob'
21
Q

LET VARIABLE

A

let can be re-assigned but not changed

This will assign a variable much like var, but with a little bit different behavior. Most notably, it differs by creating “block-level scope”.

let firstName = 'Alice';
firstName = 'Bob';
22
Q

Primitive Data Types (String, Number, Boolean)

A

Primitive data types, also known as basic data types are the simplest data types in JavaScript. They’re sort of like primary colors in that all other data types (which we will learn about in later lessons) are made of these types.

23
Q

Strings

A

Strings are blocks of text. They will always be defined with quotation marks around them, either single or double. Any text with quotes around it (even numbers) are strings.

const dog = 'fido'; <<<<< STRING>>>>>
const string = '2'; <<<<<>>>>
24
Q

Numbers JS

A

Numbers are just that, numbers. Numbers do NOT have quotes around them. They can be negative as well. JavaScript does have a limitation on the size of a number (+/- 9007199254740991), but only very rarely will that limitation come up.

const answer = 42;
const negative = -13;
25
Q

Booleans JS

A

Booleans are an important relic from the origins of computer science.
It is a dichotomous concept that powers binary code, still the very core of computers.

You may have seen binary code in the past (e.g., 0001 0110…). That is Boolean logic.

The only booleans in JavaScript are true and false, traditionally written in lowercase letters. These variables are useful when you need to employ some kind of dichotomous (or “yes”/”no”) logic in your code.

const iLoveJavascript = true;<<<>>
const isThisaString = false;<<<>>

Note that while Booleans look like strings, the lack of ‘ around the words indicates that the variable is a boolean and it will work differently under the hood.

26
Q

Undefined and Null JS

A

There are a couple of JavaScript objects that don’t really fit into any type. Those are the values undefined and null. You will get undefined when you are looking for a variable that does not have a value yet. undefined simply means what you are asking for does not exist.

console.log(unkownVar); // undefined

null
is an object that we, the developers, set when we want to tell other developers that the item they are looking for exists, but there is no value associated with it. While undefined is set by the JavaScript language, null is set by the developer. If you ever receive null, it means that another developer has set that value to null.

let phoneNumber = '123-456-7890';
phoneNumber = null;

phoneNumber; // null

One last thing to note, neither undefined nor null are strings. They are written just as they are without quotes around them, like a Boolean.

27
Q

FUNCTION SCOPE VARIABLE example

A
function example () {
   if (true) {
     var myVar = 'Hello';
}
console.log(myVar);
}
example();<<>>>
28
Q

BLOCK SCOPE VARIABLE EXAMPLE

A
function example() {
 if (true) {
  let myLet = 'Hello';
}
 console.log(myLet); <<<<<>>>>
}
example();<<>>>
29
Q

GLOBAL VARIABLES EXAMPLE DO NOT DO THIS

A
globalVar = 'Do not do this';
let alsoGlobal = 'Global';
function example() {
  console.log(alsoGlobal);<
30
Q

Standard Operators

A

1 + 1; // returns 2
2 * 2; // returns 4
2 - 2; // returns 0
2 / 2; // returns 1

const num1 = 2
const num2 = 2

num1 + num2 // returns 4

const string1 = 'My name is'
const string2 = 'Bob'

string1 + string2 // returns ‘My name is Bob’

31
Q

% MODULO OPERATOR

A

Something you may not have seen before is the modulo operator (%). This math operator will divide two numbers (integers or floats) and return only the remainder. For example, 10 / 3 is 3 with a remainder of 1, so 10 % 3 (read as ‘10 mod 3’) will return 1 .

DIVIDES ALL MATHMATICAL NUMBERS
21 % 5; // returns 1
21 % 6; // returns 3
21 % 7; // returns 0

32
Q

Math.pow

A

We can use the pow method on Math to return a number raised to an exponent. It will take two numbers. The first is the base and the second is the power. For example, Math.pow(5,2) calculates 5 squared, which is 25. See some more examples below:

Math.pow(2,2) // returns 4
Math.pow(3,2) // returns 9
Math.pow(3,3) // returns 27

33
Q

Math.round, Math.floor, Math.ceil

A

Math also has methods that will round numbers for us. .round will round a number to the nearest whole number. .floor will always round a number down to the nearest whole number. .ceil will always round up to the nearest whole number.

Math.round(6.5) // returns 7
Math.round(6.45) // returns 6
Math.floor(6.999) // returns 6
Math.ceil(6.0001) // returns 7

34
Q

Truthiness

A

In these lessons, we have talked a lot about the Boolean values, true and false. When using an if statement or other statements that expect a Boolean value (such as the !, NOT), if the expression given is not a Boolean value, JavaScript will do something called type coercion and transform whatever it is given into a Boolean value. This is known as “truthy” and “falsey” - yes, seriously. Every data type has some truthiness to it. Here are some examples:

// items that are interpreted as true
true
1
‘ ‘
[] // an array, you’ll learn more about this later
{} // an object, you’ll learn more about this later
function() {}

// items that are interpreted as false
false
0
undefined
null
''
35
Q

Comparison Operators

A

JavaScript has a number of comparison and logical operators, (> >= < <= === !==). These operators work just as they would in math: greater than, less than, greater than or equal to, and all the rest. We use these operators to evaluate two expressions. As the computer runs the code, the operator will return either a true (if the statement is true) or a false (if the statement is not true).

1 > 2; // false
2 < 3; // true
10 >= 10; // true
100 <= 1; // false

The “triple equals” sign ( === ) must not be confused with a single equal sign (which indicates assigning a value to a variable). The triple equal will compare everything about the two items, including type, and return if they are exactly equal or not. (Something to note: there is also a “double equals” ( == ) sign which will compare two items, but it allows type coercion so a string and an integer can be considered equal (1 == ‘1’ // true). Due to this, it is considered bad practice to use the double equal sign. We would like to see you always using the triple equal sign, and you will always see us using it.)

1 === 1; // true
1 === ‘1’; // false
‘cat’ === ‘cat’; // true
‘cat’ === ‘Cat’; // false

First is the “NOT” (!). When you see this it will mean that we are asking the opposite of the expression (we will revisit the NOT operator later in this lesson). With that in mind, we can introduce the “not equals” ( !== ) sign. This will return true if the items are NOT equal to each other, in any way. This, like the triple equal sign, takes type into account.

1 !== 1; // false
1 !== ‘1’; // true
‘cat’ !== ‘cat’; // false
‘cat’ !== ‘Cat’; // true

36
Q

Logical Operators

A

We can also combine two equality expressions and ask if either of them are true, both of them are true, or neither of them is true. To do this we will use Logical Operators.

&&

The first logical operator we will look at is the “AND” operator. It is written with two ampersands (&&). This will evaluate both expressions and will return true if BOTH expressions are true. If one (or both) of them is false, then this operator will return false. For example, (100 > 10 && 10 === 10) will return true because both statements are true, but (10 === 9 && 10 > 9) will return false because one statement is false.

||

Next up is the “OR” operator. It is written with two vertical bars ( ). This operator will check two expressions and return true if either one is true. It will return false only if BOTH expressions are false. As you’d expect a line where both parts are true would return true. Like so:

(100 > 10 || 10 === 10) //true

Similarly this line where only one expression is accurate, would return true. Like this:
(10 === 9 || 10 > 9) //true

If both expressions are false, like this, then the result will be false.

!
The last logical operator is the “NOT” operator. It is written as a single exclamation mark (!). We saw this operator earlier when determining equality (!==). As before, the NOT operator will return the opposite Boolean value of what is passed to it. In this first case, since the opposite of false is true, (!false) would return true.

(!false) // true

Similarly, since 1 is equal to 1 and this statement is true, !(1===1) would return false thanks to the! operator.

(!(1 === 1)) // false

37
Q

Notes About Logical Operators

A

A couple things to note about logical operators. The expressions are evaluated in order, and the computer will skip any redundant expressions. In an && statement, if the first expression is false, the second expression will not be evaluated because BOTH expressions need to be true. Same for the || statement. If the first expression is true, the second will not be evaluated because there only needs to be one true statement to fulfill the requirements of the operator. Use parentheses. As we saw in the second ! operator example, we used parentheses to evaluate what was inside of the parentheses FIRST, then applied the ! operator. We can wrap ANY expression in parentheses and it will be evaluated before evaluating the expression as a whole.