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

Ben Attenborough
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ben Attenborough
Front End Web Development Techdegree Graduate 32,769 Points

Is JavaScript redundant?

This might seem a strange question. I've been studying web development for a few months now and one of the things that has been bugging me is what is the use of sinking time into JavaScript when good practice states that website needed to function without JS.

What this means is that the site needs to be fully functional without JS and the JS is just there to "enchance" the site for those browsers with scripts switched on.

The implication of this seems to be that JS is essentially decoration for a web site. And yet given the power of JS and the great things it can do it seems wasteful to restrict its usage to bit of visual enhancement.

I'm currently doing a project which involves users filling out a form. I know I could use JS to validate the data entered into the form, but of course I also need a fallback in case the user has disabled javascript (in case a malicious user tries to circumvent the JS validation in order to insert malicious code into my database). As such I need to do data validation AGAIN in PHP. In this case it seems yet again that the JS is redundant (sure it can provide nice visual prompts for user validation which would be harder / less visually attractive to do with PHP, but its functional element of preventing bad data is redundant).

So I am left in the position of avoiding the use of JS until the end of each project when I may use it to provide some non-critical visual enhancements to the site. Which just seems a waste.

2 Answers

Kevin Korte
Kevin Korte
28,149 Points

One word: User Experience.

It's a really really important aspect of it. It's way more than just throwing some glitter on at the end. User experience is one of the most important things in developing a successful website.

Also, just a side note. You would never ever only validate a form in JS. It HAS to be validated on the server side. JS validation was never meant to protect against form submissions, but rather provide instant validation feedback instead of waiting for a form submit. That's a huge UX plus. Any malicious user worth their salt can just change your JS validation rules to allow their malicious activity to pass through, since JS is client side. Or they can just turn JS off.

If you're curious as to how much of a role it plays in UX and your impression of a site, try going JS free for a day or two in your normal day to day web browsing and see how it feels.

Ben Attenborough
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ben Attenborough
Front End Web Development Techdegree Graduate 32,769 Points

Yup, all fair enough comments and my question may look naive to me in a few months time but I thought it was a important question to ask. It can be frustrating just starting out to discover that a lot of the cool things you want to do require fallbacks or are impossible if you want your site to be fully compatible. I like the suggestion that JS is for UX, and also the idea of going JS free for the day. I'll give that a whirl at some point.

I accept the form validation bit was naive!

Kevin Korte
Kevin Korte
28,149 Points

We've all asked the same question I think at one point or another. I know I did. Even with the JS validation. No biggie. We learn from experience, or the experience of others.

But seriously, go about your normal business with JS off for a day or two, especially when it's sites you are familiar with already. You'll get a good idea how to work with or without it.

You might be surprised with Facebook does when you try to go to it on a desktop with JS disabled.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

There's still a huge place for JavaScript IMO. A massive place. It's the biggest and for me the go to Front End Technology for websites and the place to start for learning Web Programming.

But of course not everyone uses JavaScript so a fall back but must be used but it doesn't make it redundant!