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

JavaScript Object-Oriented JavaScript Object Basics Dot Notation & Bracket Notation

Chris Shaffer
Chris Shaffer
12,030 Points

Why is a variable being declared without the use of "let" or "const"?

In the first video, right at the start of the Workspace using fruits.js a variable "fruitsLength" is set as equal to the fruits array length fruits.length.

Neither let nor const is used to declare this variable.

I understand there are particular ways (that are usually not recommended) this can be done, but why is it being done in this video? It's a distraction, and IMHO bad practice.

I'm doing this video as a part of a review before I start a new app (and believe me, I'm very comfortable with JS and objects) and I can say that in 4+ years of writing JS professionally I have never used an undeclared variable without var/let/const.

1 Answer

Steven Parker
Steven Parker
231,275 Points

You're quite right, implicit globals are not good practice. You may want to make a bug report to the Support staff. Fixing the video might not be easily done, but they might add something to the Teacher's Notes about it.

And you might get an "Exterminator" badge! :beetle:

Chris Shaffer
Chris Shaffer
12,030 Points

Thanks. I shot them an email about it just now.