Node.JS Flashcards

1
Q

For Js’s Node.js, what’s the process you must go through everytime you start a new web development project? Include the installaton of express.js and it’s command line code.

A

1 - Create a new directory;

2 - Create a file called server.js inside it (backend);

3 - Initialise npm with server.js as the starting point;

4 - Install express in the directory (command line:”npm install express”).

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

How are new elements added to a list in JavaScript?

A

“listName”.push

(this will add the new elements to the end of the list)

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

What code in JavaScript would print out a list of severally added numbers and substitute numbers divisible by 3 with Fizz, number divisible by 5 with Buzz and numbers divisible by both with FizzBuzz?

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

In JavaScript, what code can give out a random element from a list?

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

How are elements removed from a list (array) in JavaScript?

A

“listName”.pop

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

Additive; Equality; Shift; Multiplicative; Postfix; Relational and Unary.

From the list above, choose one and state its precedence position in relation to the others; and its associativity.

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

Bitwise AND; Logical AND; Conditional; Bitwise OR; Bitwise XOR; Logical OR; Assignment and Comma.

From the list above, choose one and state its precedence position in relation to the others; and its associativity.

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

In software testing, what is a edge case?

A

An extreme on either side of the spectrum.

You must test your code under extreme conditions.

Always think about the cases where your program may be asked to divide by 0.

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

In software testing, what is a corner case?

A

Just like an edge case but with multiple parameters.

For example, anything dividing by 0 should be undefined but what if both operands are 0?; anything divided by itself should be 1.

The best way to deal with this is to create an exception for when both operands in a ratio have the same value.

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

In Web development, what is the best practice in terms of positioning of the external CSS link vs the external JavaScript link?

A

The CSS link should be in the

section and the JavaScript link should be at the very end of the code, before the tag.

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

In JavaScript, what function is used to chage the content inside a given (say h1) HTML tag into “xxxx”?

A

“h1.innerHTML = “xxxx””

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

In JavaScript, what does “.querySelector(“xxxx”)” do?

A

It look through the entire document for “xxxx” and selects it for firther action.

For example:

“document.querySelector(“input”).click();”

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

In Oblect Oriented Programming (OOP), what is the difference between a method and a function?

A

A method can only be used when associated with an object.

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

List the main decision-making statements.

A

if-then;

if-the-else;

switch;

goto.

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

List the main looping statements.

A

for;

while;

do-while.

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

List the main branching statements.

A

break;

continue;

return;

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

Visualize a code in Javascript that generates a fibonacci sequence in an array with n elements.

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

In JavaScript, what does the below code do?

A

It selects all elements with a certain tag name and presents the results as an array (see code, below).

To effect changes to the array elements, the array index position of that element must be specified.

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

Visualise the funtionality of ‘.querySelectorAll(“ “).style.color(or any other property) = “red” ‘

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

In JavaScript, what will the code below do?

A

It will change the queried element to the opposite state whenever activated in the console.

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

What does “function signature” mean?

A

It is the name of the function as well as the parameters that it defines. It’s its esasential identity.

See, for example, Python’s “print” function signature.

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

In JavaScript, what is special about “.querySelector( )”

A

You can combine elements inside it to produce a more specific query.

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

What does the below JavaScript code do?

A

It selects the first “a” element and returns all the attributes associated with it.

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

What does the below JavaScript code do?

A

returns the attribute’s value.

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

What does the below JavaScript code do?

A

It changes the value of the specified attribute to the value specified in the second parameter of the setAttribute method.

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

In JavaScripti what is the difference between “(li a)”,

“(li.item)” and “(#list .item)”

A

represents id’s;

. represents classes;

and

just the element name represents HTML elements.

If there is a space, it signifies a hierarchical relationsip from left to right.

No space signifies colleague relationship (inside the same<>).

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

Summarise the “for” loop syntax.

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

Visualize a simple example of a four-layer nested index in Python.

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

Visualise code, in JavaScript, that uses a loop to iterate over a set of elements and that uses an event listener to each. When each element is clicked, made them change the font color to white.

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

How is a constructor created in JavaScript?

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

In HTML code, how can attributes be easily defined and found?

A

Attributes are everything that goes inside a <> other than the tag name itself.

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

In JavaScript’s jQuery framework, what does the code below do?

A

It changes the property (first parameter) of the selected element. The values to be changed into is the second parameter.

42
Q

In JavaScript’s jQuery framework, what does the code below do?

A

It represents the current property (defined in the .css method) of the selected element.

It can be “console.log”-ed or “alerted” etc…

43
Q

In jQuery, how are multiple classes added to a selected element?

A

Put a space between classes in the .addClass method.

46
Q

To a computer, what is the difference between 12.0 and 11.999999999999999?

A

None. The computer relies heavily on approximation. For precise calculations of this kind of precision, special libraries are required.

48
Q

What are the three programming components that allow for the imlplementation of any algorithm?

A
  1. Sequence: ordering statements sequencially;
  2. Selection: making decisions (if-then, switch etc);
  3. Iteration: looping or repeating (for, while, do-while etc)
49
Q

Visualize code in JavaScript that is made to create a Simon game program.

Use jQuery syntax to select the button with the same id as the randomChosenColour.

A
50
Q

Visualize code in JavaScript that is made to create a Simon game program.

Declare two arrays; one, called buttonColours, with the colours red, blue, green and yellow as elements and the other, called gamePattern, empty.

Then, create a function called nextSequence that produces a random number between 0 and 3 and returns one of the colours in buttonColours as well as adding that colour to gamePattern array.

A
51
Q

Visualize code in JavaScript that is made to create a Simon game program.

Use jQuery syntax to select the button with the same id as the randomChosenColour and to make it flash.

A
52
Q

Visualize code in JavaScript that is made to create a Simon game program.

Use javascript syntax to assign a sound from a sound file to each button.

A
53
Q

Visualize code in JavaScript that is made to create a Simon game program.

At the top of the game.js file, create a new empty array with the name userClickedPattern.

Use jQuery to detect when any of the buttons are clicked and trigger a handler function.

Inside the handler, create a new variable called userChosenColour to store the id of the button that got clicked: So if the Green button was clicked, userChosenColour will equal its id which is “green”.

Add the contents of the variable userChosenColour to the end of the userClickedPattern variable.

console-log it.

A
54
Q

Visualize code in JavaScript that is made to create a Simon game program.

  1. Use jQuery to detect when a keyboard key has been pressed, when that happens for the first time, call nextSequence().

You’ll need a way to keep track of whether the game has started or not, so you only call nextSequence() on the first keypress.

  1. Create a new variable called level and start at level 0.
  2. The h1 title starts out saying “Press A Key to Start”, when the game has started, change this to say “Level 0”.
  3. Inside nextSequence(), increase the level by 1 every time nextSequence() is called.
  4. Inside nextSequence(), update the h1 with this change in the value of level.
A
55
Q

For the JavaScript Simon game, visualize code that attaches a sound to each click event on a coloured button.

A
57
Q

In object oriented programming (OOP), what are the two distinct relationship types represented by Inheritance versus Composition?

A

Inheritance represents a “is” relationship between the parent and child classes;

Composition represents a “has”/”contains” relationship between classes.

59
Q

In JavaScript, how can you tell if a funtion is a constructor function?

A

The first letter of the function name is also capitalized; eschewing the rules of camelcasing.

61
Q

In JavaScript, where should the jQuery CDN tag be placed, in relation to the index.js tag?

A

Above it.

62
Q

What is “minification” and why do we minify code?

A

it’s the removal of all spaces and indentations from code( as the browser doesn’t care about them).

This speeds up the rate at which the browser downloads your page and improves user experience by making your page load faster.

66
Q

In jQuery, what does the .hasClass method do?

A

It returns a boolean value to express if the specified class is applied to the selected element.

67
Q

In jQuery, what is the difference between the .text method and the .html method?

A

The .text method takes everything inside the parameter as text while the .html method only reads what is inside html tags; even while applying the html tag formatting to the selected element.

68
Q

in jQuery, how are attributes manipulated?

A

In the same manner as styles but using the .attr method.

69
Q

Why is documentation important? Give 3 reasons.

A

1 - If another programmer can’t understand what your function (code) does, then it is worthless as they can’t use it confidently and will have to waste time writting it again;

2 - You may come back to your code months or years later and have forgotten what the code does and without documentation you’ll just have to write it again;

3 - By documenting what your code is supposed to do, you set yourself up for success because you have a clear objective.

70
Q

How should you UX-test your programs to make sure the user will experience the program as you intended?

A

Run the program in the command prompt.

71
Q

In JavaScript Node’s REPL, how can you discover what are all the possible commands from the first couple of letters?

A

You enter the letters and the press the Tab key twice for the below result:

73
Q

In JavaScript’s Node.js, what lines of code must be present in a javascript project file that will be able to manipulate a computer’s file system?

A
74
Q

What’s the line used to create a npm package.json file in a directory?

A

“npm init”

75
Q

What’s the line used to install a npm package?

A

“npm i (package name)”

76
Q

In Node’s, how to you exit REPL?

A

By either entering “.exit” or pressing “Ctrl+C” twice.

79
Q

What is the backbone code to creating an express server?

why do we bind word “app” to the express module?

A

Using the word “app” is best pratice from convention.

80
Q

In Node.js, how can you make the command line notify you that a server is listening?

A

Create a callback funtion in the “.listen()” method.

81
Q

In web development, what does “localhost:xxxx” conote?

A

It conotes the route of any website i.e. the web point of entry.

82
Q

How do you enable your server to respond to a request from the route page using express.js?

How are responses to calls from others pages in your web project done?

A

You use the “.get()” method with 2 parameters: the first one is the route of your website (“/”) and the second one is a callback funtion with two parameters (request(req) and response(res)).

Inside the callback function, make the server send a response to the browser by using the “.send()” method.

84
Q

In JS’s Node.js, how is a file ran from the command line?

A

“node (file name)”

85
Q

For Js’s Node.js, what’s the process you must go through everytime you start a new web development project? Include the installaton of express.js and it’s command line code.

A

1 - Create a new directory;

2 - Create a file called server.js inside it (backend);

3 - Initialise npm with server.js as the starting point;

4 - Install express in the directory (command line:”npm install express”).

86
Q

In the Hyper command line, how do you open a directory (folder) using a given program?

A

make sure the command line location is the directory you wish to open and enter:

“(program name) .”

87
Q

In Node.js, how in body-parser incorporated into your server file?

A
92
Q

What npm package is used to run a server that automatically updates when you make changes to your server.js file?

How do you run that server from the command line?

A

nodemon.

run it by entering “nodemon (file name)”

93
Q

Visualise the Node.js boilerplate code for all web projects.

A
94
Q

In Node.js’s express, what line is used to indicate the current location of a file? Give an example of its use when sending a server response with a file called index.html.

A

app.sendFile(__dirname + “/index.html”);

95
Q

In web development what do the status codes mean?

A

100’s - Hold on (wait);

200’s - Here you go (Ok);

300’s - Go away (security concerns);

400’s - You messed up (you did something wrong);

500’s - We, the developers, messed up (We did something wrong).

96
Q

In Node.js, what does the body-parser module do?

A

It allows us to parse the information sent to the browser from a post request and use that information.

98
Q

In Node.js, what body-parser method do we use parse html form data?

A

“body-parser.urlencoded({extended: true})”

99
Q

In Node.js, what is used to convert body-parser values into floats?

A

parseFloat()

100
Q

In wed development, what do JSON, XML and HTML stand for?

A

JSON = Javascript Object Notation;

XML = Extensible Markup Language;

HTML = Hypertext Markup Language.

101
Q

JSON Viewer Awsome

A

Yes, JSONViewerAwesome. com

102
Q

Give one example of a binary file.

A

An image file.

103
Q

As a rule of thumb, how would you decide between a switch statement and a string of else-if statements?

A

If there are 5 alternatives or more, use a switch statement.

104
Q

Visualize a simple EJS template that says what day of the week it is using a variable called “day”.

A
105
Q

What syntax must be used to run CONTROL-FLOW code inside an EJS file? Where should you place most of your code?

A

The scriptet tag must be used.

Use them around EVERY Javascript element. You should however, keep most of your logic inside your app.js (server) file.