Given the following code:
var s = "Hello";
var x = s.toLowerCase();
var l = s.length;What are the types of the following?
sxs.toLowerCase()s.toLowerCases.lengthl
In var x = 5 + 6;, what is +?
- Function
- Operator
- Number
- Aggregator
In var x = 5 + 6;, what is var?
- Variable
- Keyword
- Operator
- Constant
Given the following code:
var x = z[y];What is y?
- Index
- Key
- Index or key
- Array
Given the following code:
var y = 1;
var x = [1, 2, 3];
var z = x[y];What is y?
- Index
- Key
- Index or key
- Array
Given the following code:
var joe = {
name: "Joe",
age: 24,
};
var joesName = joe.name;
var joesAge = joe["age"];- What is
'age'in the last line?- Index
- Key
- Array
- Object
- What are
nameandageof the objectjoe?- Index
- Key
- Object
- Property
Given the following code:
var y = "length";
var x = [1, 2, 3];
var z = x[y];What is y?
- Index
- Key
- Index or key
- Array
What is the element for index 1 in array x?
Fill in: "The value of the (...) length of x is (...)"
What is the name of these functions?
function a() { return true; }var a = function b() { return true; }var c = function () { return true; }
Write a function that has two parameters, called first and second.
Write a function call that passes three arguments.
Write code for the following:
- Declare a variable called
xand initialize it with the string "Hello". - Declare a variable called
yand initialize it with the propertylengthofx. - Declare a variable called
zand initialize it with the result of calling the methodtoUpperCaseonx - Declare a function called
myFunction. This function should take two arguments, and should call the second argument with the first argument as its argument. Then, declare a variable calledfand initialize it with an empty anonymous function, and callmyFunctionwith the arguments10andf.
Explain as precisely as possible (in English) what the following code does, line by line.
(Tip: it should look like the items in the previous question!)
var s = "HackYourFuture";
var i = s.indexOf("Your");
function sum(a, b) {
return a + b;
}
var s = sum(4, 5);
var r = Math.sqrt(s);For each of these, indicate whether it is an expression or a statement:
ll = 4;l == 4if (l == 4) { console.log("yes"); }console.log("yes");"yes"console.log(l == 4 ? "yes" : "no")function a() { return 4; }var a = function () { return 4; }
How can you tell whether something is a statement?
How can you tell whether something is an expression?
Given the following code:
var s = "Hello".toLowerCase();
var l = s.length;
function sum(a, b) {
return a + b;
}
var max = function (a, b) {
return a > b ? a : b;
};
var s1 = sum(4, 5);
var s2 = 4 + 5;
if (s2 == s1) {
console.log("same");
} else {
console.log("not same");
}List all 11 statements in the code above.
Bonus question!
List all 28 expressions in the code from Q18.