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 AJAX Basics Programming AJAX Introducing JSON

Elena Man
Elena Man
21,092 Points

Completing the requirement with JS instead of PHP

Could someone please explain to me why this particular problem is best solved with JS instead of a backend language like PHP?

For example, PHP could check the database to see if the employee is in the office or not and then output the HTML code accordingly. Why is JS needed in this case?

3 Answers

Steven Parker
Steven Parker
229,732 Points

In many cases, the front-end developer has no access to the back-end programming. But code in JS generally runs in the browser, so it can be used to create front-end solutions that would work in all cases.

One thing that could be done with JS is to allow for a real-time update of the employees' statuses. So for example, if John goes out to lunch, his status would change to "Out". If the JS made an AJAX call periodically (say, every 30 seconds), then the sidebar could be changed on the fly while someone is still reading whatever page they're viewing instead of seeing it the next time they go to another page.

Is it possible now to use Full-Stack JavaScript and use Node + Express for the back-end scripting? I know the MERN stack has gained more popularity in recent years.

Steven Parker
Steven Parker
229,732 Points

Yes, Node is specifically a JavaScript engine for running code in the back end, and Express is a framework for creating Node applications.