Week 1 Flashcards
What does console.log(…) do in the Node.js environment?
Prints the given argument to the standard output, or terminal
It outputs to the stream known as STDOUT
What is the difference to fork and clone a code repository?
Fork copies the repository on the server, and clone copies it to the local disk
Fork is an action used on GitHub to copy a repo to your account
What will be logged to the console?
var globalScope = ‘I'm all up in your codes!’;
if (true) {
let globalScope = ‘Not anymore, you're not!’;
}
console.log(globalScope);
I’m all up in your codes!
The let declaration is scoped to it’s containing block, which means that our console.log() ignores it completely.
What will be logged to the console?
x = 12;
if(true) {
x + 2;
x = 4;
}
console.log(x);
4
x is set as a global variable, and is not contained inside any function or block scope. It is overwritten inside the conditional statement, and retains it’s new value when the block closes.
What will the following code output to the console?
undefined
E.T.
friend is hoisted to the top but given no value, therefore the first console.log will say undefined. Then, the value “E.T.” is set to friend before the second console.log which will output “E.T.”.
The functions createUser, or sendUserData are examples of which naming convention?
Camel Case
What is meant by type coercion?
When the operands of an operator are different types, one of them will be converted to an equivalent value of the other operand’s type
an example is the comparison operator == in JavaScript
What is meant by type coercion?
When the operands of an operator are different types, one of them will be converted to an equivalent value of the other operand’s type
an example is the comparison operator == in JavaScript
What would the following JavaScript code evaluate to? Why?
‘0’ == false
true
‘0’ and false would be coerced to a common type and evaluate to be equal (or true)
Would the following JavaScript code evaluate to true or false? Why?
‘1’ === 1
false because the variable types are different
Which of the following is not a primitive data type in JavaScript? Boolean, Array, Number, String?
arrays are a type of Object in JavaScript, not a primitive
Name a valid way to access an object value?
myObject[‘key’]
you can access object values using square bracket notation
myObject.key
you can access values using .key notation
Are primitive data types the same across most programming languages?
No, primitives are a defining feature of a programming language
Primitives are similar, but often unique to a given programming language
Is the following code a valid Object in JavaScript?
var myObjected = {
‘key-1’: 42,
keyB: ‘value B’,
‘keyC’: [1, 2, 3]
};
Correct, the object would work despite inconsistent key definitions
Given the following object, how would you access the first borough, Manhattan (using JavaScript)?
var nyc = {
name: ‘New York City’,
boroughs: [
‘Manhattan’,
‘Queens’,
‘Brooklyn’,
‘The Bronx’,
‘Staten Island’],
population: 8491079,
area_codes: [212, 347, 646, 718, 917, 929],
position: { lat: 40.7127, lng: -74.0059 }
}
nyc[‘boroughs’][0]
This would return the first element of the boroughs array
In programming, what is meant by the term First-class citizen (or First-class object)?
An object with no restrictions on its creation, destruction, or usage
This includes the ability to be passed as an argument, returned from a function, and assigned to a variable