https://www.youtube.com/watch?v=IVIlN22XDGQ
https://www.youtube.com/watch?v=VHigeqECFVQ
https://www.youtube.com/watch?v=W7awzvRbmqY
https://www.youtube.com/watch?v=DL5TTbyo64o
1. Python Tutor
Write a program to find the smallest value in an array.
Use http://pythontutor.com/ to visualize your code.
2. Common Errors - Run the following code snippets and observe errors.
(If you are using a language other than JavaScript, try to recreate the same errors in your language)
ReferenceError: variable is not defined
let arr = [1, 2, 3]
ar.push(4);
TypeError: Cannot read property 'x' of undefined
function doubleArrayElements(arr) {
let b = [];
for (let a of arr) {
b.push(a * 2);
}
return b;
}
Silent errors - mostly due to type coersion
Adding string to number
let x = 1;
let y = "2"
console.log(x + y);
Adding a number to an array
let arr = [1, 2, 3, 4];
let y = 5
z = arr + y;
console.log(z)
Dividing by 0
console.log(1 / 0);
Parse Int - NaN
let word = "hello"
let number = parseInt(word);
function square(n) {
return n * n;
}
console.log(square(number));