Do you need new JavaScript to work in ServiceNow?
Jace's Blog
·
Oct 17, 2024
·
article
Sometimes you need new code converted to things ServiceNow understands. Arrow functions now work in ServiceNow in some places but not others. let, const same thing.
Here's a way to take any new script and make it work. This is called transpiling. It's complicated. The way I understand it is, you give it new code, and it makes it work with and older set of JavaScript features that were available a long time ago using polyfills.
Enough dry stuff let's get trying it.
Go to [babeljs.io/repl](https://babeljs.io/repl/?utm%5Fsource=jace.pro&utm%5Fmedium=newsletter&utm%5Fcampaign=do-you-need-new-javascript-to-work-in-servicenow) and set the target to, defaults, ie 11.
Then paste in the new JavaScript. Or if you want something to start with try pasting this code.
```
let a = ()=>{
console.log(message);
}
// see let becomes var
// and () => {} becomes function(..)
// lets try other things
//
let [red,green,blue] = [0,1,2];
// copying into a new object
var person = {
name: "Jace",
location: "MN"
}
/*
// if you uncomment this, it will add a polyfill to do this
let copy = {
...person
}
*/
```
That should become something like;
```
var a = function a() {
console.log(message);
};
// see let becomes var
// and () => {} becomse function(..)
// lets try other things
// spread
var red = 0,
green = 1,
blue = 2;
// copying into a new object
var person = {
name: "Jace",
location: "MN"
};
/*
// if you uncomment this, it will add a polyfill to do this
let copy = {
...person
}
*/
```
---
[Powered by beehiiv](https://www.beehiiv.com/?utm%5Fcampaign=75630be7-4f27-4df2-9d9a-d1a5bc018206&utm%5Fmedium=post%5Frss&utm%5Fsource=jace%5Fs%5Fblog)
https://jace.pro/p/2024-10-17-do-you-need-new-js-to-work-sn