Skip to content

Latest commit

 

History

History
executable file
·
85 lines (70 loc) · 2.06 KB

w01d5.md

File metadata and controls

executable file
·
85 lines (70 loc) · 2.06 KB

HTML

  1. Take a piece of paper and draw the structure of this website

Functions and Scope

  1. Describe what a function is/does?
  2. How do I declare a function? and how do I run a function?
  3. Given the following code, what is the command to console log hello world?
var hello = function () {
  return function () {
    return function () {
      console.log("hello world");
    };
  };
};
  1. Would the following code console.log destroy the world? or would it give you an error saying b is not undefined? Explain your answer.
var a = "hello world!";
var myFunction = function() {
  var b = "destroy the worl!";
}
myFunction();
console.log(b);
  1. Would the following code console.log 25? or would it console.log 1? Explain your answer.
var a = 5;
var myFunction = function() {
  console.log(a*a);
}
var otherFunction = function () {
  myFunction = function() {
    console.log(a/a);
  }
}

otherFunction();
myFunction();
  1. What is the difference between the following code?
function add (a) {
  return a+a;
}

add = function (a) {
  return a+a
}
  1. Which of these function would work, and which one would not? Explain your answer.
console.log(a())
console.log(b())
function a () {return "321"}
b = function () {return "123"}

Objects

  1. What is an object?
  2. What are ways to create an object?
  3. What does a property in an object contain?
  4. Given the follow object. Use dot notation to get "Fer" and bracket notation to get the "Denis"
var wdi = {
  instructor1: "Fer",
  instructor2: "Denis",
  mysteriousInstructor: "Harry"
}
  1. How do I create a new property in the object above?
  2. How do I delete mysteriousInstructor in the object above?
  3. What is this and how do we use it?
  4. What is the for loop systax that is used to iterate through objects?