your answer here
your answer here
console.log(typeof a);
var a;
your answer here
console.log(typeof "hello world");
your answer here
console.log(typeof false);
your answer here
console.log(typeof 21);
your answer here
console.log(typeof null);
your answer here
console.log(typeof undefined);
your answer here
console.log(typeof { name: "John" });
your answer here
console.log(typeof typeof 42);
your answer here
console.log(typeof 3.1416);
your answer here
console.log(typeof "10");
your answer here
var person = {
name: "Peter",
age: 40
};
console.log(typeof person.name);
console.log(typeof person.age);
console.log(typeof person.lastName);
your answer here
console.log(typeof []);
your answer here
console.log(typeof ["Hello", 20, true][2]);
your answer here
console.log(typeof ["Hello", 20, true][3]);
your answer here
console.log(typeof { a: 2 }["a"]);
your answer here
var index = "c";
console.log({ a: 1, b: 2, c: 3 }[index]);
your answer here
console.log({ x: 100, y: 200 }.x);
your answer here
function getX (point) {
return point.x;
}
getX.PI = '3.1416';
console.log(typeof getX);
console.log(typeof getX({ x: 34, y: 54 }));
console.log(typeof getX.PI);
your answer here
var n = "47";
console.log(typeof n);
console.log(typeof Number(n));
your answer here
var n = "47";
console.log(typeof (n * 2));
your answer here
var a = "13";
var b = a * 2;
console.log(a); // "13"
console.log(b); // 26
your answer here
var a = "13";
var b = Number(a);
console.log(a); // "13"
console.log(b); // 13
your answer here
your answer here
Boolean('');
your answer here
Boolean('.');
your answer here
Boolean("");
your answer here
Boolean(0);
your answer here
Boolean("0");
your answer here
Boolean(1);
your answer here
Boolean(1/0);
your answer here
Boolean(0/1);
your answer here
Boolean(NaN);
your answer here
Boolean(Infinity);
your answer here
Boolean(0 + "0");
your answer here
Boolean("0" + 0);
your answer here
Boolean("0" * 1);
your answer here
Boolean(1 * "0");
your answer here
Boolean(-1 * 0);
your answer here
Boolean(null);
your answer here
Boolean(undefined);
your answer here
Boolean(false);
your answer here
Boolean(true);
your answer here
Boolean([]);
your answer here
Boolean([1, 2, 3]);
your answer here
Boolean([0].toString());
your answer here
Boolean([1, '', {}][1]);
your answer here
Boolean([1, '', { n: 0 }][2].n);
your answer here
Boolean([].toString());
your answer here
Boolean({});
your answer here
Boolean({}.toString());
your answer here
Boolean({ name: "Doe" });
your answer here
Boolean({ toString: function () {
return '';
}}.toString());
your answer here
Boolean({ number: 0 }.number);
your answer here
Boolean({ char: 'a' }.char);
your answer here
Boolean(function noop() {});
your answer here
your answer here
your answer here
your answer here
your answer here
"12" == 12;
your answer here
12 === "12";
your answer here
1 == true;
your answer here
true === 1;
your answer here
false == 0;
your answer here
false == "false";
your answer here
"" == false;
your answer here
null == false;
your answer here
undefined == null;
your answer here
false == undefined;
your answer here
0 == "";
your answer here
0 == null;
your answer here
var a;
a == null;
your answer here
({} == {});
your answer here
({} === {});
your answer here
[] == [];
your answer here
[1, 2, 3] === [1, 2, 3];
your answer here
[1, 2, 3] == "1,2,3";
your answer here
NaN == NaN;
your answer here
NaN === NaN;
your answer here
(function noop (){}) == (function noop (){});
your answer here
(function noop (){}).toString() == (function noop (){});
your answer here
2 > "1";
your answer here
"a" < "b";
your answer here
3 < "a";
your answer here
"3" < "a";
your answer here
0 > NaN;
your answer here
identifier | is valid? |
---|---|
Name |
your answer here |
0duck |
your answer here |
last.name |
your answer here |
$account |
your answer here |
_age |
your answer here |
-price |
your answer here |
car[123] |
your answer here |
for |
your answer here |
your answer here
a = 10;
foo ();
function foo () {
a = 5;
console.log(a);
var a;
}
var a;
console.log(a);
your answer here
your answer here
var a = 1;
function foo () {
if (a == 1) {
var b = 2;
}
console.log(b);
}
foo();
your answer here
var a = 1;
function foo () {
if (a == 1) {
let b = 2;
}
console.log(b);
}
foo();
your answer here
function foo () {
var a = 10
}
foo();
console.log(a);
your answer here
function foo () {
a = 20
}
foo();
console.log(a);
your answer here
18. Write the code to log if a number is even
or odd
using the if
statement, switch
statement and the conditional operator ?:
aka ternay operator
Clue: you can determine if a number is even
if the remainder of n
divided by 2
is equal to 0
. Use the remainder operator %
.
if
Solution:
// your code here
switch
Solution:
// your code here
ternary
Solution:
// your code here
your answer here
function yummy () {
a = 50
}
yummy();
console.log(a);
your answer here
'use strict';
function yummy () {
a = 50
}
yummy();
console.log(a);
your answer here
Functions are the primary mechanism of _____ in JS.
your answer here
22. Create a function square
that takes one parameter number
that returns the result of that number
multiplied by itself. You need to perform this in 3
different ways
Solution:
// your code here
Solution:
// your code here
Solution:
// your code here
your answer here
// your code here
your answer here
function createHello (greeting) {
return function greet (name) {
return greeting + " " + name + "!";
}
}
var greetInSpanish = createHello('Hola');
console.log(greetInSpanish("Pedro"));
console.log(createHello('Hi')("Mike"));
your answer here
// Kitties
function sayHello() {
console.log("Hello " + this.name);
}
var name = "Fluffy";
sayHello();
var kitty = {
name: "Buttercup",
sayHello: sayHello
};
kitty.sayHello();
sayHello.call({ name: "Cocoa" });
new sayHello();
your answer here
var animal = {
walk: "I'm walking!"
};
var bird = Object.create(animal);
bird.fly = "I'm flying!";
var penguin = Object.create(bird);
penguin.fly = "I can't fly :(";
penguin.swim = "I'm swimming!";
var canary = Object.create(bird);
var tiger = Object.create(animal);
console.log(tiger.walk);
console.log(tiger.fly);
console.log(canary.fly);
console.log(canary.walk);
console.log(canary.swim);
console.log(penguin.fly);
console.log(penguin.walk);
console.log(penguin.swim);
your answer here
28. What are the two main techniques to make older browsers work with newer features available in JS? Describe each
your answer here
your answer here
2.1 Create a module in an IIFE
stored in a variable calculator
that exposes 4 methods: plus
, minus
, times
and dividedBy
. Each method should receive one parameter firstNumber
and return a function that receives another parameter secondNumber
. Every method should perform the operation it describes, for example, it's expected that plus
adds the firstNumber
to the secondNumber
, dividedBy
should divide the secondNumber
by the firstNumber
and so on. The idea is to have "stored" the firstNumber
to perform the next operations with it.
TIP: You can create a script.js
file and test your code in the browser or node.js.
Solution:
// create your calculator module here
var calculator;
// Do NOT touch this code
const testCases = [
{ type: "plus", n1: 3, n2: [1, 2, 3], expected: [4, 5, 6] },
{ type: "minus", n1: 1, n2: [1, 0, -1], expected: [0, -1, -2] },
{ type: "times", n1: 5, n2: [2, 5, 10], expected: [10, 25, 50] },
{ type: "dividedBy", n1: 10, n2: [10, 100, 1000], expected: [1, 10, 100] }
];
const result = testCases.every(test => {
const operation = calculator[test.type](test.n1);
return test.n2.every((number, i) => {
const testPassed = operation(number) === test.expected[i];
if (!testPassed) {
console.log(`Expected: ${operation(number)} to be: ${test.expected[i]}. Operation: secondNumber(${number}) ${test.type} firstNumber(${test.n1})`);
}
return testPassed;
});
});
console.log("All tests passed: ", result);