JS101 Assessment Flashcards
We have to learn how to do some new thigns for this assessment, what are they.
2 categories
2 things in first
1 consideration in second
Implementation level description, Describe with perfect accuracy what is happening line by line
- Understand the terms for everything, the specific delineations between concepts
- talk in terms of return, output, mutation, non local variables being used
User-level description
- just enough information that another developer can use it in their code without first having to understand what’s going on behind the scenes.
What is the difference between: “function declaration”, “function expression”, “function definition”, or “function invocation”
Function declaration
function funcName() {
}
function expression
let funcName = function() {
}
The main difference is that a function expression can be used as ananonymous and immediately invoked.
Also function declarations can be invoke before they are called
function definition- To create the function body, and set the parameters of the function. There are 3 ways, expressions, declarations, arrow
function invocation, when the code block of a function is executed
Highlight any specific syntactical conventions or technical observations where relevant.
incomplete
Identify the fundamental concept or concepts demonstrated by the question.
incomplete
Describe this
let greeting = ‘Hello’;
while (true) {
greeting = ‘Hi’;
break;
}
console.log(greeting);
The global variable greeting is declared and initialized to the string ‘Hello’ on line 1. Lines 3 to 6 define a loop that will execute forever, unless something happens to end the loop. When the loop begins, it first reassigns the greeting global variable to ‘Hi’ on line 4. The next line, break, causes the loop to end, with execution resuming after line 6. Finally, on line 8, console.log is called with the value of the variable greeting passed to it as an argument. Since greeting is now assigned to ‘Hi’, that is what gets output.
This example demonstrates variable scoping rules in JavaScript; specifically the fact that a variable declared in the outer scope is accessible from a nested inner scope.
Why was the previous description so good?
compared to:
A) greeting is set to ‘Hello’ on line 1. greeting is set to ‘Hi’ on line 4. Line 8 outputs greeting, which is ‘Hi’.
B) The global variable greeting is assigned to the string ‘Hello’ on line 1. Within the loop, greeting is then reassigned to the string ‘Hi’ on line 4. On line 8, console.log is called with the variable greeting passed to it as an argument; since greeting is now assigned to ‘Hi’, this is what is output.
C) The global variable greeting is initialized to the string ‘Hello’ on line 1. Within the loop, lines 3 to 6 define a block within which greeting is reassigned to the string ‘Hi’ on line 4. On line 8, console.log is called with the variable greeting passed to it as an argument; since greeting is now assigned to ‘Hi’, this is what is output
Answer A describes what is happening in the code example, but does so in a fairly basic way with imprecise language. This response wouldn’t be sufficient to receive full points for any of the questions in the assessment.
Answer B again describes what is happening, but with greater precision of language. This answer would score higher than answer A, but generally wouldn’t be sufficient to receive full points for the majority of questions; most questions in the assessment are looking for something more, such as a specific piece of syntactical knowledge and perhaps identification of some fundamental concept.
Answer C, as well as precisely describing the example, identifies an important JavaScript syntactical convention that is relevant to the example code: the fact that braces next to a while statement form a block in JavaScript. We also use more precise terminology by saying that greeting is initialized instead of assigned. For some assessment questions, this answer might be enough to receive full points, but many questions expect you to demonstrate a deeper understanding of the fundamental concept that this illustrates.
Answer D goes a step further than C by explaining why this is important and the underlying principle that it demonstrates; i.e., the fact that JavaScript has particular scoping rules which affect whether or not a variable can be referenced or reassigned. It also talks about how the break statement influences the execution of the loop. Finally, we also mention that we’re declaring a global variable. Based on the way that this question is phrased, answer D would be the only answer of the four to receive full points in an actual assessment.
“Assignment of variable” to “value or value to variable”
Both are fine but be consistent per session.
Is const a variable?
Are function parameters variables?
Are function names variables?
Are object keys variables
Variables:
Variables declared with let or const (even though it can’t be “variable”)
Function parameters
Function names
Not Variables:
Object keys, or object property names
Are truthy things true?
No, they evaluate to true when converted to boolean
A
Are variables passed to or returned by functions?
B
What’s the difference between arguments and parameters
A.
No. Calues or references are passed.
B.
Parameters are the names assigned to a function’s arguments; arguments are the values that get passed to the function.
What game can you play as you think about how you explain things?
Explain it like they are a student who sort of understand the concepts but need a reminder of every little thing. Explain why we’re talking about it, (what it demonstrates), then explain what happens (vs maybe what one might assume), you explain how it happens (the code itself), and
More examples
https://launchschool.com/lessons/3c44cca7/assignments/c433c127
https://launchschool.com/lessons/018b0797/assignments/54fa0cc9
Idiomatic naming
https://launchschool.com/lessons/3c44cca7/assignments/27f312f5
What is a checklist of things you need to consider when describing what’s going on with code?
What overall is going to happen
What is mutated? What is returned?
Declarations, initializations, assignments, reassignments
Define a loop
Invoke a function
Function expression vs function declaration
Scope, shadowing
What this problem demonstrates or What the key pieces of JS knowledge we needed to know to tackle this problem
Another word for mutating
destructive