JavaScript Function Assignment Gotcha

Looks harmless, right? But it gave me a very beautiful output ❌ Cannot read properties of undefined. As I didn't put ';' at the end of the function assignment, JS thought i want to access the property of the function. so now its like Array.prototype.customMap = function() {  console.log(this) }[1,2,3].customMap(); Result: Cannot read properties of undefined. Lesson learned that lines starting with [ or ( are dangerous without ; #JavaScript #FrontendDevelopment #LearningInPublic

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories