1

Note: I know this is probably a simple and basic question but I just started to learn Javascript a couple of year ago when all these changes started taking place and it seems I learned the old version.

I'm confused with Javascript. I'm trying to implement a basic MEAN stack. I'm using es6 Javascript with Nodejs (6.x) on the server side. Then for the client side, I'm using Angular 1.5 in es5 Javascript, but it seems to not be working.

Is is possible to mix es6 on server-side and use es5 on client-side OR is all or nothing... all es6 on both server/client or vice versa?

UPDATE Thanks for all the info. I've been looking at ES6(ES2015) and it doesn't seem that hard, I've even written some code in it with success. However, I just got a handle on Angular 1 a while back and then it seems like Angular 1.6 and up came out and was quite different. Angular 1 had quite the learning curve, how hard would it be to update my Angular 1 code into 1.6 or above? Is the newer Angular written in ES6? All frontend JS written in ES6 needs a tranpiler or can browsers handle ES6 now?

4
  • 2
    "it seems to not be working" doesn't tell us much. If you're seeing errors, you should post them. If you're not seeing errors but things still aren't working, you should describe what isn't working in more detail (e.g. http request isn't being sent or it's sending the wrong headers, etc.). Commented Apr 27, 2017 at 17:59
  • 2
    ES5 code won't throw error just because it's old Commented Apr 27, 2017 at 17:59
  • Es6 has no deprecations of Es5, it's suposed to work properlly if you have es6 available on server-side. Although, I suggest using ES6 on both sides and traspile it to es5 when needed. Commented Apr 27, 2017 at 18:01
  • Your server and client shouldn't be exchanging actual code, so why would it matter to the server what is running on the client, or vice-versa? Commented Apr 27, 2017 at 18:02

2 Answers 2

1

Is is possible to mix es6 on server-side and use es5 on client-side OR is all or nothing... all es6 on both server/client or vice versa?

It's possible to mix entirely separate languages on the server and client, such as PHP or Java or Ruby or C# on the server and JavaScript on the client. So yes, it's just fine if you want to use ES2015 (aka "ES6") and later features in your server-side Node code and restrict yourself to ES5 and earlier features in your client-side browser code.

You don't have to, though, and it's surprisingly hard once you get used to writing let and const and arrow functions to make yourself not write them in your client-side code by accident. So for that reason, you might consider using ES2015+ plus both server-side and client-side, and "transpiling" your client-side code from ES2015+ down to ES5 for use on older browsers. There are multiple transpilers, such as Babel. You can develop with an up-to-date browser such as Chrome or Firefox or Edge, and then have your build tool make the "production" build pass all the client-side code through Babel (perhaps with Webpack or Browserify or similar) for use on older browsers such as IE11.

Sign up to request clarification or add additional context in comments.

1 Comment

@user3125823: I'm not a big Angular guy, so not the right person to address those new questions. But the big decision you have is Angular 1.6 vs. Angular 4, which is the latest. v1.6 has a big following. v4 is the latest in the "v2" line (they switched to semantic versioning), which was a framework rewrite.
1

Is is possible to mix es6 on server-side and use es5 on client-side

Yes you could mix both. But be aware that sharing code between both could be tricky.

is all or nothing... all es6 on both server/client or vice versa?

That's not the case here, but I would recommended to use on both sides es6 and convert to es5 for the browser, eg with Babel

3 Comments

Seems to be quite advanced for someone who can't seem to differentiate the two :p, but indeed!
This is a fine opinion... but there's not much fact here. It also doesn't answer the question, which is whether it is possible. Also, all recent browsers support ES6 by now, is there a reason to downgrade?
agree, have edited my post. @WilomGfx it easier IMO as you don't really need to know the differences.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.