Node.JS Flashcards
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.
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 are new elements added to a list in JavaScript?
“listName”.push
(this will add the new elements to the end of the list)
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?
In JavaScript, what code can give out a random element from a list?
How are elements removed from a list (array) in JavaScript?
“listName”.pop
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.
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.
In software testing, what is a edge case?
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.
In software testing, what is a corner case?
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.
In Web development, what is the best practice in terms of positioning of the external CSS link vs the external JavaScript link?
The CSS link should be in the
section and the JavaScript link should be at the very end of the code, before the tag.
In JavaScript, what function is used to chage the content inside a given (say h1) HTML tag into “xxxx”?
“h1.innerHTML = “xxxx””
In JavaScript, what does “.querySelector(“xxxx”)” do?
It look through the entire document for “xxxx” and selects it for firther action.
For example:
“document.querySelector(“input”).click();”
In Oblect Oriented Programming (OOP), what is the difference between a method and a function?
A method can only be used when associated with an object.
List the main decision-making statements.
if-then;
if-the-else;
switch;
goto.
List the main looping statements.
for;
while;
do-while.
List the main branching statements.
break;
continue;
return;
Visualize a code in Javascript that generates a fibonacci sequence in an array with n elements.
In JavaScript, what does the below code do?
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.
Visualise the funtionality of ‘.querySelectorAll(“ “).style.color(or any other property) = “red” ‘
In JavaScript, what will the code below do?
It will change the queried element to the opposite state whenever activated in the console.
What does “function signature” mean?
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.
In JavaScript, what is special about “.querySelector( )”
You can combine elements inside it to produce a more specific query.
What does the below JavaScript code do?
It selects the first “a” element and returns all the attributes associated with it.
What does the below JavaScript code do?
returns the attribute’s value.
What does the below JavaScript code do?
It changes the value of the specified attribute to the value specified in the second parameter of the setAttribute method.
In JavaScripti what is the difference between “(li a)”,
“(li.item)” and “(#list .item)”
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<>).
Summarise the “for” loop syntax.
Visualize a simple example of a four-layer nested index in Python.
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.
How is a constructor created in JavaScript?
In HTML code, how can attributes be easily defined and found?
Attributes are everything that goes inside a <> other than the tag name itself.