Skip to content

Instantly share code, notes, and snippets.

@lucabertolasi
Last active February 27, 2018 21:27
Show Gist options
  • Save lucabertolasi/bdbf548808586cf597cd0ab2763844e7 to your computer and use it in GitHub Desktop.
Save lucabertolasi/bdbf548808586cf597cd0ab2763844e7 to your computer and use it in GitHub Desktop.
#just4fun | [JavaScript] Does your JS work? Evaluate it out! Google will come to rescue if necessary :)
/**
* @license
* Copyright (c) 2017, Luca Bertolasi. All Rights Reserved.
*
* This source code is licensed under the terms of the MIT license,
* a copy of which can be found at https://choosealicense.com/licenses/mit/
*/
function evalOrGoogle(str) {
const ELLIPSIS = `\u2026`
console.log(`Evaluating '${str.substr(0, 10)}'${ELLIPSIS}`)
try {
console.log(`${ELLIPSIS}it works!\n`, eval(str))
return true
} catch (e) {
const ERROR_URL = encodeURI(`https://google.com/search?q=js ${e.name} ${e.message}`)
console.log(`${ELLIPSIS}humm, maybe this can help: ${ERROR_URL}`)
window.open(ERROR_URL, `_blank`)
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment