NEW
Font size
Worksheets#100 Devs - LwL - class 15
Total questions: 25
Worksheet time: 13mins
What are variables?
They are ways to store data in the computer memory
Data Buckets
Boxes
All are correct
How to declare and assign values to variables?
let variableName = "this is a string"
variableName = "this is a string"
Ways to assign values to a string type of variable?
single quote', "double quote", or `backticks`
single quote', "double quote"
What is the difference between === and ==
Three equal signs compares type and value, and two equal signs compares only value
Three equal signs compares only value, and two equal signs compares type and value
const age = 17
if (age >= 18){
console.log("you can get in")
} else if (age > 16) {
console.log("you're not quite ready")
}else {
console.log("You're too young")
}
What will this code return?
"you're not quite ready"
"you can get in"
"You're too young"
const fishSpecies = "clownfish"
const inhabitat = "anemone"
if (fishSpecies === "clownfish" && inhabitat === "anemone"){
console.log("welcome home, nemo")
} else{
console.log("only clownfish is allowed in the anemone")
}
What will this return?
"welcome home, nemo"
"only clownfish is allowed in the anemone"
if (name === "leon" && hair ==="gorgeous"{ //run code } What must be true so the code runs?
name must be Leon and hair must be gorgeous
Either name must be Leon or hair must be gorgeous
What are functions?
They are sets of instructions, that can be reused whenever called/run
They are instructions to be used once
function add(??, ???){
// function body
}
parameters
arguments
add( ??, ???)
arguments
parameters
What are truthy values?
Truthy values are evaluated as true in a boolean context.
if (2) {
//do something - will always execute because number 2, when evaluated, will be true just for existing
}
Truthy values are values that can be evaluated as true or false in a boolean context.
if (0) {
//do something
}
What values are always evaluated as falsy?
false, 0,"", null, undefined, and NaN
false, null, undefined, and NaN
What is the structure of a for loop?
for(let i = 0; i < 5; i++) {
//do something with i
}
for (i = 0, i++, i < 5){
//do something with i
}
let i = 0
while (i < 5){
//do something with i
i++
}
When should you choose a while loop instead of a for loop?
When you don't know exactly when you reach the end condition
When you know exactly when to end the loop
What is an array?
It is a way to organize multiple "things" in JS using a single structure
It is a named indexed structure in JS, as in "name" : "Leon Noel"
How to declare an array with literal notation?
let leonsArray = [ ]
let leonsArray = new Array()
How to store the first element from an array in a variable?
let firstElement = array[0]
let firstElement = array[1]
How to figure out the length of an array?
leonsArray.length
leonsArray.length()
let leonsArray = [1,2,3,4]
How to console.log the last element of an array?
leonsArray[leonsArray.length-1]
leonsArray[4]
let leonsArray = [1,2,3,4]
what will console.log(leonsArray[5]) return?
undefined
5
""
let leonsArray = [1,2,3,4]
How can we redefine the second element of the array to 7?
leonsArray[1] = 7
leonsArray[2] = 7
let leonsArray = [1,2,3,4]
How can we element in the first index of the array to 7?
leonsArray[0] =7
leonsArray[1] = 7
let leonsArray = [1,2,3,4]
What will
for( i = 0; i < leonsArray.length; i++){
console.log(leonsArray[i]+3)
}
do?
It will log every single element added by 3 on the console
It will log every array index added by 3 on the console
It will log every element and index added by 3 on the console
let leonsArray = [1,2,3,4]
What will
leonsArray.forEach(element => {
console.log(element)
})
do?
It will log each element of the array: 1, 2, 3 and 4
It will log the indexes of the array: 1, 2, 3, 4
This is a trick question:
let leonsArray = [1,2,3,4]
leonsArray.forEach(element => {
element + 3
})
What will console.log(leonsArray) return?
[1,2,3,4]
Do you know why? If not, MDN array forEach
[4,5,6,7]
Do you know why? If not, MDN array forEach
