December 2017
Beginner
372 pages
10h 32m
English
Arrays are a very common example of where JavaScript dynamic typing fails. We define an array variable, score, which has the list of scores in it. To fetch the selected elements from an array, we use the slice function. Till the time score is an array, this works, but imagine if someone wanted to assign a single element in an array and instead they assigned a number. Now the same slice function will fail:
var score = [1,2,3,4,5,6];console.log(score.slice(2, 4)); // returns: [3,4]score = 10;console.log(score.slice(2, 4)); // Uncaught TypeError: score.slice is not a function
Read now
Unlock full access