Which version of JavaScript?! | XM Community
Question

Which version of JavaScript?!


Userlevel 1
Badge

Hello community,
I can't find any information about which version of JS is supported in Qualtrics. Again and again, this makes it difficult to decide which functions may be used in custom code and which functionalities I have to find workarounds for.
For example: A little while ago, I discovered that using 'async await' is not possible in Qualtrics -> it gave me an error message while trying to save it. I actually found a related question in this community, but it was never answered.
Thanks so much in advance!!


10 replies

Userlevel 3
Badge +8

jQuery is what is being used by default on top of the JFE. See link: Add JavaScript (qualtrics.com)

Userlevel 1
Badge

Thank you so much for your reply! I'm so glad someone found this question :)
I'm afraid it doesn't fully answer my question, though. Given that I'm not new to programming per se, but don't have a computer science etc. background, I'll try to summarize my knowledge about my specific current problem in simple terms:
I was aware of Qualtrics using the JavaScript Form Engine (JFE), which executes our custom JS Code added to a survey. jQuery is a by default available library that can be used in our code. BUT which JS version is supported is a different question, isn't it (e.g., ES6, ECMAScript 2018, ... ; see https://www.w3schools.com/Js/js_versions.asp)?
I'm currently trying to use the 'includes()' command from the JS version 'ECMAScript 7' (see https://www.w3schools.com/Jsref/jsref_includes_array.asp). I can't get it to work. Qualtrics lets me save the code without error message, but the code snippet using 'includes()' doesn't produce the result it should.
I think I'm able to find another solution for what I want using jQuery, but still, it would save much time in the future to know which JS version's commands I can or cannot rely on.

Userlevel 1
Badge

Okay, I just tried to use 'array.indexOf()' (from ECMAScript 1) instead of 'includes()'. This, too, does not work in Qualtrics, I get the same wrong results.
I tried out both code snippets in two different online JS compilers each, and all four scenarios work as intended, so I'm sure there is no other mistake in my code.
Next, I tried to use 'jQuery.inArray()'. This doesn't work in the two online compilers, but apparently that's okay because they just might not be supporting jQuery. However, this code also does not work in Qualtrics which I thought supports jQuery?!
At this point, I'm pretty confused and have no more ideas what I might be doing wrong...

Userlevel 3
Badge +8

TomG might be able to help. My JS knowledge is limited.

Userlevel 7
Badge +27

Annie2538 - The JavaScript version is based on the browser being used by the respondent. So, there isn't a "Qualtrics Supported" version.
You can see what JavaScript functions are supported by different browsers at websites like https://caniuse.com or https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/
When creating JS you need to try to stick to functions that are supported on the lowest common denominator of the browsers you expect or allow respondents to use.
By 'allow' I mean you can add code or logic to detect the browser being used and terminate respondents that are using an unsupported browser.

Userlevel 3
Badge +8

https://www.qualtrics.com/community/discussion/comment/35470#Comment_35470Thanks Tom

Userlevel 1
Badge

TomG Thanks so much for your answer, it really helped me to better understand the problem (and will be helpful for the future)!
In this case, imho it doesn't make any sense that the solutions I found to be working in the online JS compilers don't work in Qualtrics (while using the same browser)... Also I don't know why the jQuery solution doesn't work.
I'll keep on trying stuff out and debugging... :)

Userlevel 7
Badge +21

Annie2538 All the three methods you've mentioned, are legacy methods. Unless you're using something like a Netscape Navigator or IE8, they should work out of the box.
Also, you mention that you're getting the "same wrong results", if they weren't working in Qualtrics, there's a possibilty that the logic you're using may have some issues. Ideally, if a method is not recognized, the browser should throw an error.

Userlevel 7
Badge +27

Annie2538 - You've mentioned 'JS compilers' a couple of times, but JS isn't compiled. If you are really talking about minified and/or obfuscated you have to be careful with the settings. You should always first test non-minified and non-obfuscated first. Once you know it is working you can minify/obfuscate and then test again.

Userlevel 1
Badge

TomG - Thanks for your reply, I really appreciate the effort.
What I meant with 'online compilers': I've been writing my JS code in an offline editor of which I did not know it can directly run JS up until 5mins ago. Up to yesterday, I used to copy my code into 'online compilers' (that's what some of them call themselves, so I thought it's correct) like https://jsfiddle.net and let it run there to check the results.
However, I didn't know the terms 'minify' and 'obfuscate' yet and just educated myself on this. So thank you! :)
Last night, I also found out what was wrong with my programme. I'll post the answer later today, just for the sake of completeness.

Leave a Reply