# Erro : Untaught SyntaxError: unexpected token 'var'

**URL:** <https://discourse.processing.org/t/erro-untaught-syntaxerror-unexpected-token-var/17733>\
**Category:** Coding Questions\
**Created:** [February 11, 2020, 2:24pm UTC](https://discourse.processing.org/t/erro-untaught-syntaxerror-unexpected-token-var/17733 "2020-02-11T14:24:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonhard](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@Leonhard](https://discourse.processing.org/u/Leonhard)\
**Post date:** [February 11, 2020, 2:24pm UTC](https://discourse.processing.org/t/erro-untaught-syntaxerror-unexpected-token-var/17733/1 "2020-02-11T14:24:59Z")

</div>

Hi, I’m trying to convert this code to JavaScript, but this error appears: “Untaught SyntaxError: unexpected token ‘var’”.

Converted code: [https://www.openprocessing.org/sketch/839422/embed/](https://www.openprocessing.org/sketch/839422/embed/)

Original code: [https://www.openprocessing.org/sketch/20105/embed/](https://www.openprocessing.org/sketch/20105/embed/)

---

<div class="post-metadata">

**Author:** ![black](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/black/32/477_2.png) [@black](https://discourse.processing.org/u/black)\
**Post date:** [February 11, 2020, 2:57pm UTC](https://discourse.processing.org/t/erro-untaught-syntaxerror-unexpected-token-var/17733/2 "2020-02-11T14:57:06Z")

</div>

Dont use class in P5JS. You need to convert class into javaScript functions.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 11, 2020, 3:39pm UTC](https://discourse.processing.org/t/erro-untaught-syntaxerror-unexpected-token-var/17733/3 "2020-02-11T15:39:03Z")

</div>

> [@black](#):
>
> You need to convert `class` into JavaScript functions.

> **[class - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class)**
>
> The class declaration creates a binding of a new class to a given name.

---

<div class="post-metadata">

**Author:** ![black](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/black/32/477_2.png) [@black](https://discourse.processing.org/u/black)\
**Post date:** [February 11, 2020, 3:43pm UTC](https://discourse.processing.org/t/erro-untaught-syntaxerror-unexpected-token-var/17733/4 "2020-02-11T15:43:25Z")

</div>

I know that but isn’t it ES6 syntax? does P5JS support ES6 syntax? BTW I check he was getting error at

` var [] tailPath;`  
which isn’t a JavaScript code. He is still using class defined in java structure.  
it should be

`var tailPath = [];`

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 11, 2020, 3:44pm UTC](https://discourse.processing.org/t/erro-untaught-syntaxerror-unexpected-token-var/17733/5 "2020-02-11T15:44:13Z")

</div>

1st thing you’re gonna need is switch the engine from “Processingjs” to “P5js”.

Also read this wiki about transition from Processing’s Java Mode to p5js:

- [GitHub.com/processing/p5.js/wiki/Processing-transition](http://GitHub.com/processing/p5.js/wiki/Processing-transition)

And the link below got many sketches w/ both Java Mode & p5js versions:

> **[r/processing - OpenProcessing: converting code written in Java to JavaScript](https://www.reddit.com/r/processing/comments/7dqqvh/openprocessing_converting_code_written_in_java_to/dq0ecac/)**
>
> 10 votes and 14 comments so far on Reddit

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 11, 2020, 4:00pm UTC](https://discourse.processing.org/t/erro-untaught-syntaxerror-unexpected-token-var/17733/6 "2020-02-11T16:00:05Z")

</div>

> [@black](#):
>
> I know that but isn’t it ES6 syntax?

Have you seen the compatibility table for the `class` keyword?

- [class - JavaScript | MDN](http://Developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class#Browser_compatibility)

Chrome since version 49 (42 under ´strict mode´).  
Firefox since version 45. And so on.

Chrome v42 & v49 were released in 2015/Apr/14 & 2016/Mar/02 respectively:  
[https://en.wikipedia.org/wiki/Google\_Chrome\_version\_history](https://en.wikipedia.org/wiki/Google_Chrome_version_history)

While Firefox v45 was released in 2016/Mar/08:

> **[Firefox 45.0, See All New Features, Updates and Fixes](https://www.mozilla.org/en-US/firefox/45.0/releasenotes/)**

So it has been about 4 years we have the `class` keyword available in major browsers!

> [@black](#):
>
> Does P5JS support ES6 syntax?

p5js is a JS library. We can write ES6 code and use ES5 libraries w/ no worries.

---

<div class="post-metadata">

**Author:** ![black](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/black/32/477_2.png) [@black](https://discourse.processing.org/u/black)\
**Post date:** [February 11, 2020, 6:11pm UTC](https://discourse.processing.org/t/erro-untaught-syntaxerror-unexpected-token-var/17733/7 "2020-02-11T18:11:55Z")

</div>

Yeah, anyway. OP need to put a lot of effort to convert java code to JavaScript code for sure. Both of us not gonna do it for him. He better need to read the link provided by you and get to it. If returns with actual problem while implementing it then we can help him.
