Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Alexei Parphyonov](https://secure.gravatar.com/avatar/1029cb155a90d74100ac0e32336b8770?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Alexei Parphyonov
34,128 PointsArrow Function Syntax doesn't seem to be working
Hei. I wanted to write passwordEvent according to Arrow Function Syntax, but it doesn't seem to be working, while it works with traditional function declaration. I get the following mistake
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
at n.fn.init.val (jquery-1.11.0.min.js:4)
at HTMLInputElement.passwordEvent (app.js:15)
at HTMLInputElement.dispatch (jquery-1.11.0.min.js:3)
at HTMLInputElement.r.handle (jquery-1.11.0.min.js:3)
The function itself looks like
const passwordEvent = () => {
if ($(this).val().length < 9) {
$(this).next().show();
} else {
$(this).next().hide();
}
};
Earlier I noticed that I failed to declare anonymous functions in events in jQuery using arrow syntax either. Are they not compatible?
And here it's opposite, I declare an arrow function outside of jQuery, but it fails to use it.
2 Answers
![Lars Reimann](https://secure.gravatar.com/avatar/01fb8d395901b595ff6914482f45b30d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Lars Reimann
11,816 PointsIt will never work with arrow functions. The value of this
inside an arrow function is determined by the surrounding scope. Since the function is in the global scope, this
will refer to the window
object. Now you are trying to get the value of the window, which is undefined and jQuery internally tries to call the method toLowerCase on undefined, which causes an error, because undefined has no methods.
![Dane Parchment](https://uploads.teamtreehouse.com/production/profile-photos/352832/micro_Dane_s_Profile_Photo_Cropped.jpg)
Dane Parchment
Treehouse Moderator 11,076 PointsThe arrow syntax only works on the EcmaScript 6 version of javascript, you will need both Node Js and Babel in order to utilize this syntax in your project, which is way outside the scope of the course you are in.