- Write a function named
hiWorld
that prints 'hello world' to the console
- Write the same function from above in 2 other ways using different syntax
- Write a function that accepts a 'name' parameter and prints "Hi, my name is
<name>
" to the console
- Write a funtion that accepts 2 numbers as parameters and returns their sum
- Write a function that accepts a number as a parameter returns the double of it
- Write a function called
logger
that accepts a string as a parameter and then passes that string toconsole.log
. Uselogger
as a callback to console.log each element in the array below.
let stringArray = ["JavaScript", "is pretty", "cool", "I guess."]
// put answer here
- Write a function that accepts a number as a parameter and prints "โ You're too young to enter the clurb! โ" if the parameter is less than 21 and "๐คก Welcome to the clurb! ๐" if the parameter is 21 or over
- Modify the above function to allow an underage patron in if they have a fake id
- What is lexical scope?
- What would be printed to the console in the example below? Why?
let carType = "Honda Civic"
function myCar(carType){
console.log(`I drive a fancy ass ${carType}!`)
}
carType('Tesla X')
- What would be printed to the console in the example below? Why?
let carType = "Honda Civic"
function myCar(carType){
console.log(`I drive a fancy ass ${carType}!`)
}
carType('Tesla X')
- Write out what would be printed to the console, in order, if the script below were run in a browser.
console.log(person)
let person = "Lady Gaga"
function someFunction(){
console.log(person)
function otherFunction(){
let otherPerson = "Madonna"
console.log(person)
console.log(otherPerson)
}
otherFunction()
console.log(person)
console.log(otherPerson)
}
someFunction()
console.log(otherPerson)
- What would be printed to the console in the example below? Why?
if(true){
let dogName = "Neikko"
console.log(`My dog's name is ${dogName}`)
}
console.log(`My dog's name is ${dogName}`)
-
In your own words, describe hoisting?
-
If I had a JavaScript file with the following code, what would happen in each of the function calls below? Why?
bark()
meow()
function bark(){
console.log("woof woof")
}
let meow = function(){
console.log("meeeeooooowwr")
}
- What will the console.log print in each of the examples below? Why?
console.log(dogName)
var dogName = "Perky"
console.log(catName)
const catName = "Houdini"
- What will the console.log print in the example below? Why?
horse = "Benny"
console.log(horse)
var horse
- With regard to hoisting, what's the difference between
let
,var
, andconst
- What are the differences between declaring variables using
let
,var
, andconst
?
- Write a function that accepts a number (e.g. x) as a parameter and returns an inner function that accepts a different number (e.g. y) as a parameter and returns the product of it and the number from the outer function.
- Using the function from above, create a function that accepts a number as a parameter and returns its double.
- If you successfully got the question above working, explain how you utilized closures to do so?
- What would get printed to the console in the example below?
let steven = {
name: "Steven",
goForRun: function(distance){
console.log(`Today I ran ${distance} km.`)
}
}
steven.goForRun // what would happen here?
steven.goForRun()