Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Why do we use extension .js instead of .jsx?

I took a very beginner React course on youtube before the Treehouse course and they saved all the components as .jsx. Is there a difference between saving it as jsx instead of js?

1 Answer

rydavim
rydavim
18,798 Points

I'm not very familiar with React specifically, but as a general short answer - there is no real difference when it comes to the file extensions in this case. Whatever bundler or compiler or such that you're using should resolve the type of file contents for you.

However, there may be some best-practices to consider. Having not gone through whatever course you're working on I can't say for sure, but it is my opinion that it's usually a good idea for non-vanilla code to use their applicable extensions. So I would personally use .jsx in this case, but practically it shouldn't really effect anything.

Edit: I'm not sure if it's related to your question, but here's a brief article about using React Without JSX.

Ty!! ^^