Rich-text Reply

Allowing Shorthand/Minified Javascript

iProspect 06-24-16
Accepted Solution

Allowing Shorthand/Minified Javascript

Currently, it is not possible to use shorthand code. For example:

var condition = true;

  console.log('The condition is true'); 
} else {
  console.log('The condition is false');
//Works in Optimizely editor

condition ? console.log('The condition is true') : console.log('The condition is false');
//Returns an error in the Optimizely editor

Are there any plans to allow this in the future? Or is there anything currently in place that's stopping shorthand code from working properly?

I think especially in the scope of testcode, saving space could be beneficial for writing tests.



iProspect CRO
robertchan 06-24-16

Re: Allowing Shorthand/Minified Javascript

The editor uses JSHint which is why you're getting the errors. The ternary operator, as you included for example, works fine (you can see through a forced parameter preview). If you'd like to prevent errors for shortcircuiting, simply wrap the line(s) of code with the following:


* jshint ignore:start */
    // No more errors for code here
/* jshint ignore:end */
Robert Chan

Experimentation Hero
iProspect 06-24-16

Re: Allowing Shorthand/Minified Javascript

Ah perfect, i was not aware of this feature. I know the code technically works, however on every iteration it would give out popup errors, so it's not really workable. I'll try the Jshint ignore comments for sure! Thanks.

iProspect CRO