Skip to content

Instantly share code, notes, and snippets.

@pietro909
Last active October 28, 2016 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pietro909/987d2015dbce8c89d259e2b72fa17c2a to your computer and use it in GitHub Desktop.
Save pietro909/987d2015dbce8c89d259e2b72fa17c2a to your computer and use it in GitHub Desktop.
A runtime error in Javascript
function contains(c, s) {
var index = s.indexOf(c);
return index > -1;
}
console.log(contains("hi", "there")); // false
console.log(contains("hi", "hi, all")); // true
console.log(contains("hi", 1)); // TypeError: s.indexOf is not a function
console.log(contains("hi", null)); // TypeError: Cannot read property 'indexOf' of null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment