logo

NJP

Tokyo ECMAScript 2021 (ES12/ecma6+ !!!) - Live Coding Happy Hour 2022-08-05

Import · Jul 25, 2022 · video

i got what [Music] welcome to the live coding happy hour where we build stuff on service now and we don't have a script and welcome to uh quite a weird episode you can zoom out down here yeah everybody welcome to a weird episode we're gonna we have a lot of our um previous advocates and some of our developer m50s joining me today to talk about something that has been repeatedly requested and if you didn't watch that video at the beginning let me let me put it again thank you for to gabby for making this book i got what the ex that's right i can't i gotta make sure i don't say script 2021 is what we're calling it in service now uh is a combination of um all a lot of the new libraries and a lot of the new methods that we have in uh more advanced javascript on the platform now that we are in the tokyo release and speaking of tokyo we could finally put up this magic um icon brad can you read yeah yeah there we go clean up the right one so we are in tokyo release as as of yesterday so the demos that i'm going to be doing are uh in a brand new instance i only got the instance this morning because i i also hit the waitlist like a lot of people did yesterday uh but we're going to be running through some of the um fun um highly requested uh advanced javascript stuff that are not advanced new stuff um that brings us up more up to date in the javascript world but first let's do some introductions we're going to start with jared to my this level this way jared go ahead hey everybody i'm jared montz um working in the product success organization here at servicenow just joined good congratulations yeah congrats jared was last week was your first week right correct yeah just finishing it around forever oh and i'm brad i work in outbound product management for next experience i'm andrew barnes uh brad and i used to be developer advocates uh in the developer program and now i am in product success management for creative workflows which uh jared just joined our team two weeks ago one week ago roughly thanks and hello i am mgopw she of many names maria gabriello ciao perez-wechter and this is chow chow he's adorable he's a realistic octopus i love him i am one of the founders of women now uh the only non-service now person on this stream right now a developer mvp two times and y'all should check out my new youtube video filled with aes okay um so if you if i gotta remember that some people have never watched this show before so if this is your first time watching live coding happy hour we are a group of people that have done development on servicenow and uh instead of trying to show you a very clean cut uh straightforward demo of things we want to show you the realistic uh the knitting gritty us painfully trying to build something sometimes it's successful sometimes it's not but we also make it we try to make it a little bit more difficult by also drinking at the same time that's what that's where the happy hour part of it comes through so now we're gonna go over in the same order and introduce our drinks that we're drinking today so uh as per tradition i usually have a form of whiskey so i'm drinking today a new one that i have never tried a star ward nova single malt whiskey uh 41 very nice today i have a bowler birch beer from the rocky mountain soda company i have a new belgium 1554 it's a dark ale brewed with spices oh it sounds so good brad i like earl today i've got a little whiskey i've got eagle rare stranger yeah well i mean i put it in here [Laughter] but it's a pretty bottle so i thought it is anna's is uh lchhh uh tradition i am a lightweight and i don't know what i have i asked my unconscious husband if i would like this passion fruit gosei and i hope i do star hill nice okay so virginia craft beer representing local nice so um the this episode's gonna be a little bit different than we have we have a true peanut gallery this time so uh i am going to be trying to show some of the new javascript capabilities i'll try to show you what i what i would have done in a pre-tokyo release and now what i can do in a tokyo release i'll be trying to jump in back and forth uh i want to give the caveat that i my my main time in tech has been in service now i was like many people started the service desk and became an admin became a developer and climbed that kind of ladder um so almost all of my javascript most of my experience has been in service now and so a lot of the new ecma 6 8 12 everything all that's been lumped together now uh i'm still new too so um if uh if anybody that's in the peanut gallery um wants to make fun of me feel free if anybody in the chat wants to call me out and how how how do you not know that man feel free let me know but now that servicenow can run these things on the server side uh this is the amount this is the opportunity for us to kind of dive in together so let me share my screen and i'm gonna put these up and i'm gonna show you one instance is san diego my new instance of tokyo i also like that they finally updated the logo again to be the full new branding so that's cool but let's i think the part i'm most excited about for this uh release is now more stack overflow answers will actually work in my scripts [Laughter] it's you don't have to scroll down to the second or third one that's finally telling you how to do it in ecma5 instead look at that configurable admin menu that's cool oh dude i don't even know it's not up there nice oh cool yeah it's really cool look at all the new features in tokyo if you missed the episode of tech now uh make sure to go to devlink.sn slash tech now and they uh yesterday uh chuck and jeremy went through a lot of the new features in tokyo so feel free to grab that it's an hour long they breezed right through a lot of the features but take a look at that that's our own self little plug and now i'm going to get rid of our faces so we can focus on this how's the text size for everybody is that good it's looking good sir okay so first i need to show you all how to actually activate uh the new uh ecmascript 2021 uh for your applications and so as a precursor we do want to say that it is available for scoped apps right now um not in global but a global app is on the roadmap to include on this but for now it is for um sourced app so uh i can make i'll just i'm gonna make an app in uh studio just to get it done real quick uh we'll call this bouncyh um yeah and so what what you're going to show us uh earl is that this is a choice you can make on a per scoped application basis so it doesn't have to be all your scoped apps at once it can be on a per scope application because it's set at the individual application level so that's if you had like some developer you really wanted to make their life a little more difficult you could just set them to not use the es21 [Laughter] nice so as everyone can see now i wasn't global but now out that little red circle shows that i'm in a scoped app i went ahead and opened it into the application file so the sys underscore app file and down here right here javascript mode all you have to do is switch that to ecmascript 2021 or es12 and save that and now everything in the scoped app can work so i was trying to think this morning like oh how am i going to show it running in the background and everybody knows every most people that have done uh some form of configuration it has touched ipsm or um has done a business rule so i thought i will try to trigger as many of these things via business rule running on incident to show that it's working on the on the server side so i'm going to create a business new business rule so john has a really good comment uh does it matter where it's stored or where it's called from so if you yeah there you go i this this is a great thing that i would love to test on this episode uh it's the one you put on the screen here if if you uh so if i build it in a scoped app but then i call it from a global app does it work still doesn't matter where it's where it lives or where it's called from oh okay i'm with john i'm i suspect that it will uh successfully work i also uh suspect that it would work yeah i'm thinking as long as the file exists in the proper application scope it can be called from anywhere and still work i'm guessing that's the case um before we jump into some of the crazier ecmo stuff one of the ones i didn't know actually worked and i want to just point out now is i didn't know const worked inside uh previous versions but like if i um i write a quick yeah there's like a few things that uh in you know before tokyo actually worked that were later than was the es5 that was yeah and those were all poly filled in there there have been some things that you've been able to access but i think it was kind of a quiet edition it wasn't a lot of fanfare in the release for those right is because this wasn't uh replace all one of the methods just like const so i'm gonna um i have a const in this script real quick and i'm gonna um i set it up so that whenever i update the description it's gonna run the script and put something in the work notes so if i say if i just update this description real quick we'll see a work note get updated and so const works and if i let me do that real quick in the um in [Music] old instance so i'm in a san diego instance now i i pre-set up this business rule so i wouldn't have to recreate it in front of everybody but i think i get warnings if i use const in old ones i think that's what it was but now that warning's all gone gone away now that it's fully supported interesting uh yeah so see um oh you can't even use constant normal ones okay so this is it doesn't work in the previous one yeah well i will be able to save it saved okay that's cool um it didn't it did work in previous ones but it it gave an error or give it a warning when doing it so if i show this in an old instance it should work the mcrib is there okay yeah so it does work in the old ones but it does it throws that error or that warning in it parsing error but still allows for saving and a lot of the new ecmo stuff if you um try to use a new ecma in an old instance it won't even let you save the script so that's constant and constant and if you don't know what constant is uh that is basically saying that you want to declare and initialize a variable but you don't expect it to ever change so if you try to change that variable you would get an error okay i see that i see a lot of people in chat saying let try let let okay let's talk about let so i'm going to change this to let that cat let almost let's see i'm it's letting me save but if i go back to this old one and i say let uh it won't even let me save we didn't because it'll even say that let is an ex script 6 feature and it's not supported in this old instance so i can't even save this file and so let's talk about that because that's the one of the main ones that people hear and not even bring our faces back about it so because we're gonna be talking about it for a hot second here's our faces hi everyone okay um why would we use let versus um variable does anybody else want to tackle it and then i'll fill in the blanks does anybody else does anybody want to try to tackle that all right i'll fill in the things which is all of it okay let has uh is a lot is different than a lot of uh you know in a few ways from setting a variable um with var so let uh the main thing it has a lot of scoping rules around it so if you define something within with a let inside of curly braces then um it's only accessible within those curly braces that uh it's running in and so the var is accessible throughout the entire script um in most cases but that's one of the main things is the let the scoping issues are different um there's a there's a thing in um since i think 2015 they started talking about it in javascript uh it's called hoisting um and so when you hoist something in javascript that means it's being brought to the very top of the code and being in and being declared and um available there so if you've ever wrote a script inside servicenow and you wrote a function it's why you can have functions at the very end of your script but still call them at the beginning even though you were using scripts going line by line by line by line functions are hoisted to the very top of the the script and that's why you're able to call them variables and let variables are all uh hoisted to the top but variables are not just declared but they're also initialized um they're initialized with an undefined value so like if i say var x equals uh hello at the very top of the script it's hoisted at the top and says hey x exists in this script but we don't know the value yet so just set it as def undefined but if you say let um x equals 100 uh it'll bring it to the top and say hey x is going to be used um but it's uh if you try to refer to that you get a reference type error it'll fully error out it won't stay undefined um so that's that's a big difference between var and let for hoisting are you all still with me in resolve college i'm still with you yeah i got you with this stuff um it's the fun things that you get to do when you're not in a compiled language right um there's other um things like uh at the at the top let doesn't create properties on the global object um so uh if you're using it in um like client scripting it can't it doesn't access the window so let's can't get all the way up to that top level um uh there's i'm trying to remember anything else is anybody else i mean we're all kind of new at this right so every time i ask you what else you all know i'm it might be um a little bit harder because you've told us the differences is there a benefit to using let instead of r um so the scoping thing is very important like knowing um what variables have access to what is important and it also gets destroyed once the curly brace is end so that means it's a little bit more performative for performing yeah performative um what's the word performant performing yeah um uh and just knowing those differences helps you debug kind of thing and i'm trying to think i mean that's what i was told to me when i was learning about it and for javascript stuff um but yeah it's it's it's one of those situations where you don't want to have you don't want if your script is thousands of variables long you should be destroyed it shouldn't be all in the global scope basically because that's a wasteless memory in space and so so one of the things that that i would uh think that it might impact is the number of times where you might get um a conflict between your script and servicenows so the reason that we avoid using gr uh for you know when you're developing in your instance is so that you don't conflict with servicenow's uh unbounded use of gr um and i wonder if uh so i'll give this a test out and and put it back into the comments in this later i wonder if that might actually avert some of the scenarios in which you can have a conflict between that variable if you are using lead instead of var give that a try i wonder yeah i might have to upgrade my own just not gr video right i i was just thinking that the let gr video instead of rgr yeah oh the sequel the sequel to the instagram now this is this is just for some context i am a purely servicenow dev i got into development through servicenow so i know literally zero about eczema and what y'all are saying it makes sense but isn't that the point of functions already aren't my vars already getting poofed um yes and no because uh it depends on how the script and service now is brought into the overall uh system so okay so it works but it doesn't really really work and this is going to make sure it really really works sort of it's the same maybe some some more of the times maybe maybe i mean javascript right everyone just shrugs and hopes for the best um being a developer in servicenow i'm very used to this yeah so pedro says hey do arrows next and that arrow functions are always the next thing that or one of the first things that people think of for newer um ecmo stuff i i can't imagine there is a single developer out there that has wrote a script and has not wished that they could use the arrow function when they're writing a service now script especially when you search it in google and get the stack on the stack overflow saying just do this i'm gonna go all right okay um so uh an arrow function okay i'm gonna this is where i'm gonna try to do um a before and after kind of thing so in before tokyo an example uh let's pretend i wanted to join um the short description and description just as an easy example uh into the work notes so i'm going to make a function called add can you pull our uh faces off the bottom because you're about to type into that space well thank you for calling for letting me reminding me thank you for reminding me all right so i'm going to say i'm going to make a function that says uh if you give me the parameters of x and y in this function called add all i want to do is return x plus a line break and y and then we're going to go ahead and put that in the work notes uh and trigger it so work now equals add e which should be the short description and description so this is again this is the old this is an older instance in san diego it feels weird saying san diego's older like that was so much of this year already um and i'm gonna go ahead and trigger that and so it should combine the two pretty simple okay that worked perfectly fine and um with arrow functions uh this is just one of the examples of the things you can do with an arrow function i'm going to grab the same stuff to save some time and then instead it could just look like this let add equals the parameters and then an arrow and what should be returned and brad maybe you can answer this question in the chat from stephan uh will we be supporting typescript and servicenow i actually can't answer that question i have no idea [Laughter] [Music] so you should be able to to go without the return or the left and right brackets there really really yeah nope i'm flying by the seat of my pants everybody all right messed me up i'm gonna say trigger the script again and it should do the same exact thing yep so combining the short description in the description um and it changed so again the old one is creating an entire function doing that and then the new way is you can get it down all the way to one line so more arrow functions are um helpful thank you for everyone in the comments thank you um andrew for calling me out and calling basically pointing out that i'm a scrub noob at all of this but i'm figuring it out hey we're all learning together the the amount of times that i had to unlearn these to fit my code into servicenow is uh you know makes it so difficult so that i even think in not uh es5 terms so uh it it's actually uh i'm relearning those muscles as well yeah seriously um but so arrow functions arrow functions there's a lot of different ways to utilize it um i'm i have a long list of things to get through so i'm going to try to um i'm going to provide this one example and move on to the next one uh the next one i want to talk about is where's my show notes uh four of okay four of so we're gonna do so i um okay i'm gonna yeah it's gonna take someone to talk over this y-type i'm still thinking though that as a best practice i'll probably still be guiding newer developers away from just using gr even though uh phil try to make it a thing just now in chat yes they're still it's still so very i agree yeah i'm going to test it out just to see what the impact is but in general you need a more descriptive variable name anyway so just use a more descriptive you know variable name and which gr is not a descriptive variable name so you should be using something other than that anyway and you have to add it use case of it won't cause unknown weird errors sometimes when servicenow also tries to steal that variable from it when there's an occle when there's an eclipse and the moon is in virgo you know um but also it just feels like this is such a very specific current use case that i could go uh i could go in the same day work in different instances as a partner where one person one of my instances is on tokyo using this and it has it enabled in the app scope that i'm it's just so many little qualifying things that i'm never gonna sit here and be like oh yeah technically you could it'll always be just a hard fast note yeah i think that that adds to why it actually got done there's so many small things and that's why it kept getting into the idea queue and being requested year after year is because there there's just a thousand little use cases i'm not i'm not sure if we're going to talk about importing external libraries but that's that's more of um where this would have helped me out over the past few years versus just an individual code snippet or starting from scratch hypothetically speaking what would happen to an established application if i just felt like flipping it to uh es6 just without telling anybody so theoretically nothing should happen but also that's why we at servicenow made it up to the developer to decide validate and test and make sure that it doesn't have an impact oh so this isn't something i can do at 4 59 on a friday night on production i mean yeah i described it can you register to choose all the scopes and and reset it on all the scopes yeah but your script will be in global so you wouldn't be able to use uh yes [Laughter] oh that was good brad all right what did you write for us all right well i started moving forward while you were oh we feel enough air for you yeah thank you so much uh so in this one um i know i could have wrote this differently but i basically grabbed 10 short descriptions 10 the 10 latest short descriptions and put them into work notes via a four so some people would do var i equals zero and then semicolon uh i less than the worknote stop length and then semicolon uh i plus plus and then put that in here i in this case since i know i'm going to use every single one i just do a four variable ink and incidents and then iterate through that to push it into the work notes and this is beautiful well this is this is old stuff this is before oh is my face still on the screen yeah we're all still there okay there it goes um this is why it's hard to host and run at the same time but uh it did it it put all ten together and but in um so doing this in ecma uh in ecmascript 2021 uh another way to do it now is um i could say four let ink of incidents and um just say working of thought and push because it automatically accesses that um that value of the array instead of the index so as you in before you would have to say which index for each one but with four of now is capable of supported you can actually just say ink because that will skip that stuff for you so it's a little bit cleaner a little bit easier to write out and let me make sure this works before i say that success uh no you don't need to test just push it yeah there it goes so another simple um thing four of works in uh servicenow now in new ecmascript um i have so many things do i how are we doing wants to know if a weight syntax is available warren so um away and promises uh if i can get to that today um i wasn't successfully able to um get that to work when i was testing this morning so i'm not sure if i want to try to um there's so many things i could cover in the new ecmascript stuff that i don't want to uh potentially derail for the rest of the entire time failing yeah guys that means you gotta like and subscribe so you can get more content later on we're gonna milk this for all we can i do think i remember seeing that we're not actually supporting promises yeah um and i i had some thoughts about that especially because like forcing a script to await and i mean it's very traditional right away and being asynchronous and promising um results is very um a traditional um service or a very traditional javascript uh technology to be able to use but servicenow has so many things that are running synchronously and asynchronously at the same time that i don't know um if they were able to isolate it just to the script field to make sure it runs properly and so that's what i was thinking of um no so i i pulled up the documentation uh so on the doc site we go through all the javascript functions and call out which ones are supported and not and it doesn't look like any of the ones related to promises are allowed in ecmascript 2021 um i don't know if it's roadmap or not i'm not sure but um right now no um cool so i'll move on to the next one while uh everyone um yells at me in chat um we did have a question uh was this enabled by updating the rhino engine or transpiling does not know uh so no it was not it was not by updating the rhino engine so uh if you're not familiar um servicenow you know what you see in experience uh is javascript that you can build and develop in the platform and then between the java layer that servicenow is built on in that javascript that you're working on and interpreting we have we have an engine called rhino it is not owned by servicenow we consume that and they don't support these functions uh and aren't going to anytime soon uh so their their support for anything after uh es5 is very small and their road map is very small and so in order to bring these capabilities to the server-side functions of servicenow we had to instead do transpiling of these functions from what you're writing in ecmascript 2021 and what our engine can actually consume that that answer the question well enough for you brad it does i knew you were going to be good at it that's i knew it okay so excellent question though uh another new feature in ecma script 2021 that i'm showing is utilizing the map functionality and so um one of the differences between a map faces thank you i got you fam um hiding faces on the stream we've learned is important because it gives everybody the opportunity to not have to smile so that's why we um [Laughter] honestly i'm so upset about that in my own video it hurts me so much um so what i'm doing here is demonstrating what it looks like building a map um why would we use a map instead of like a traditional array or um something like that so there's a few different things besides it being more performant because of how much it's been simplified yeah thanks so many pushes when you really need it to get in the work notes double push it so um i realize it's so i mean you all know it's so hard to write the script at the same time of um trying to get things to work or in trying to explain it it's like you can stop by it's so hard to write script um okay so let me just you know what i'm just going to finish typing this script and then i'll go back and explain quick guys filler talk jared it's your turn how much of your whiskey have you had not enough the answer is not enough for for earl i'm i'm thinking some sense it's important this one burns is going down to the floor wait this you got to pluralize that as we will work hopefully so so uh for jared what was your favorite thing uh looking at you know what's what's new in tokyo what oh i thought we were gonna ask jared what his favorite part of his first week that his shiny new job was going to be we're not all as aggressive as you are gabby i'll take offense to that let me talk about my map okay so um object making an object is similar to a map and a map is basically something that just hold key value pairs um and it uh it's entirely based off of the insertion order of the keys so um the cool thing about it is that both the objects um both of any kind of value can be used as the key or value so in an object a key can only be a string name like a characters or a symbol but in a on a map it can literally be um anything that you can do in any primitive or any um uh and even another object so like um you'll see that one of the keys i have is it's a string like normal another one is it's an another object and a function or an entire function and so like i can actually get map values based off of an entire basically anything anything that is described back and the opposite side too so um getting the string saying get me the string it will find the one on the it'll find the value and then return the key so it works both ways and so crazy um one of the cool so there's a lot of cool things why map is preferable in some cases like uh that means you're not um uh you're not limited to what can be the key or value um another thing is objects um if you've ever like logged an object to the console uh you'll see that it has this like when you open the tree of um all of its objects all the stuff that it has you always see this thing called prototype and so prototype is something that is um gets initialized with every object um maps don't have any of that and so it doesn't have all the extra um uh it doesn't have a bunch of fluff that it doesn't need if you're just trying to create a an actual map like it doesn't care for all the um prototype stuff that objects have um it's simplified because a key order is um all depending on just order of entry so um everything is based off of what order you put the you've put you've um set keys and values in so it's um you can rely and you can basically uh expect the what order things are in um the side there's a size property which is inherent to it which is like the only thing you really need if you're doing basic stuff and so they're all the prototype stuff is in there but size is still there um uh i think this changed in a newer javascript but objects used to not be iterable but you can iterate through objects now um uh like if you say like four var for every variable inside this object it'll go through every key so that still works but in some javascripts it doesn't work uh there's no iteration but maps have iteration um inherently available uh like i said it's more performant um uh but one thing that you would want to use objects for so and not maps is uh uh objects because with the prototype has parsing and serialization in it so like j like the parsing and um stringifying and all that stuff that's that's part of it so like you don't have to that that's easy to do with objects and not necessarily with um uh maps so now that i've talked through all that uh thank you for coming to my ted talk let me try to run this and make sure it works i need to don't my mouth is getting dry but the only thing i have is to is burning whiskey is a little bit hard to do [Laughter] did this work so so line eight does that need to be const is that going to let you edit the map uh it should be because you're this is just the initialize the initialization of the um of the oh oh line 23. we had somebody pointed out in the chat it should be incidents i think oh thank you i do the same thing copy and paste for one character thanks pavani oh i didn't have to refresh my bad okay well the map size is correct what happened with uh um you haven't queried your incident yeah every time i didn't query that incident oh my goodness okay i never do that i used to do that all the time too oh looks like a chat chat is caught up to us as well thanks santosh yeah so you'll see here that um uh i was able again the the weir the crazy thing about mapping is like i said hey get me the key value give me the value of the key and i gave the key value of a function of an entire function and i knew what to do with it and it gave me the right one so that's one of the cool things about maps cool that was a long one let me um i guess i could talk about set so set uh is like building an array huh i'll i'll just show the base i'll show the beginning of building a set but i won't run it just because um i can't think of a good use case right now for it so if i create a set we'll uh you would add things to sets like this um my set dot add so you would do my set and as long as you keep adding things it works the cool thing about sets though um if you do something like this it already knows that it's already there and all values inside of the set have to be unique and so um what this would what the array would look like in this um so right here it would be it would just be hello uh here it would be hello and then one and then uh the same thing here so it it doesn't error it doesn't um bark at you it just says hey you've already tried to add this that's fine um i'm not going to do anything with it so that's one of the cool things about uh sets um and then the other way to use it is oh this is why i was remembering why i would use this um it's faster than includes so if you if you have an um array and you try to do includes uh it it'll return a true or false if it has that thing inside the array um but for sets the add the has function so my set as uh one and it'll return true um but because it's such a simplified um array it returns so much faster so that's one of the uh things it so the benefit is it's faster and it requires uniqueness so this is the reason why you would use this over like an array beautiful i could have used that a month ago well in what use case i was iterating making a scripted rest api iterating through a table name that was passed in and and building a list of all the columns and then we had a uh a deny list that would prevent certain columns from being queried and so it just ended up looping through um each record um a couple of times and i tried to refactor it twice and it ended up getting slower after i refactored it um so with what we what we're looking at here uh i'm sure this would have cut the the processing time in half um i'm getting like sweaty at the same time this is like common for me um okay so i'll move on the next thing and i want to talk about simple because this one is fun this is useful for i mean a lot of these things are like you're going to be using every single day maybe arrows you'll use every single day but um some of these things are like oh if i had if this was available that one time like jared just said like my life would have been so much easier because this i know this caused me a headache and so um uh one thing i'm gonna do is i'm just gonna fake i don't wanna keep typing out glide records i'm gonna say this number you want some typing time errol yeah please cool so uh andrew time for a question for you from staphon how does es6 impact script includes any changes there yeah so it's gonna be the same so one i i typed the answer in oh you did and and so any server side scripting so we're looking at business rules name right now but we could just as easily be working in a script include that's referenced in a business rule and so any script include in a scoped app that has the higher level javascript enabled so that is a drop one thing i'll note there is that is a drop down and as we move into future releases we'll be enabling higher versions so they're they're named per year so we have right now enabled the 2021 versions likely by utah we might be looking at enabling the 2022 version and we'll keep that 2021 version as a choice and just add new options so any scoped app that has server side scripts in it will be affected when that is enabled oh wow so this isn't just a one-time es6 upgrade this is uh servicenow is going to make this a thing now yeah so now that we have the infrastructure and process in place to support this sort of um you know transpiling we can support new uh you know versions of this javascript functionality as they're rolled out or much much closer to when they're rolled out uh than we have before so that's exactly continue to see new new versions available in future releases okay thank you for the this it's so great when everyone jumped i did a little ajb fill as opposed to polyfills okay so um quickly symbol is um a way to for enforce uniqueness in the system and so the easiest way for me to demonstrate that is here you'll see that i have a object that it's not going to change or anything like that in fact i'll i'll put this as constant um and then i have an array and i'm going to push it twice into the same array and then i'm going to do a second array and push it twice with symbol attached to it and then we're going to evaluate the first one see if the first op first index is the same as the second index uh in one array and then the same thing the other way even though it's the same thing copied twice uh four times basically so let me save that and trigger it i wonder which string would look like by the end of it and so you'll see the first one says true but the second one says false it's because symbol in the background in this in this back end basically attaches a unique identifier to whatever is being declared inside of that uh in its parentheses inside of its parameter and so this is a good way for you basically to ensure some level of uniqueness if you're handling a lot of objects a lot of having a lot of values that need to be pushed into a list or of some sort and so that um there's no form of like duplication kind of thing um so that that's one of those cases it's something to keep in mind that you have access now too every single call is guaranteed to return as a unique symbol so that's um the fun part i don't think i've ever seen that before it looks really cool um how are we doing we're not we're not oh man i still have three four five i have like five more topics i could talk about but we're running short on let's have let's pick default parameters spread well let me get which one i want default parameters can i vote for that yeah we'll do default parameters and template strings that should be faster because you already have a function you already have functions yeah yeah yeah okay um default parameters is simple uh i won't i'll just show it so that everyone has it in their head so say i have um a function and i'm returning x plus y like this and i'm going to call it default parameters is this as simple as saying uh hello there and so if you ever were to call the that function and not include oops let me say x if you were to call it and not include it then uh it will default to that parameter um there were ways to do that inside see it appended hello there because it didn't have a y there's ways to do that in older one but you would basically have to do it inside the script itself so like if you'd be like if y is null uh basically and then um declare it there but now you can do it right in the parameters so that's that's default params let me jump to another one let's talk about ooh this is like lightning round i like this lightning round um uh i keep doing this right when i'm trying to do multiple lines and stuff like that but now you can do template strings you could do but x equals uh backtick that's the um if you ever type code or anything on slack or discord or anything like that that's what it is uh i don't know um that works now it knows that is a um it includes line breaks within the the script so now i kind of disappointed that the syntax didn't move it over but i'm glad it works yeah what if i pretty high that's what it wants to do shift tab yeah and it maintained it for you boom now you know now the number of times that that would have been useful as well i know like building dummy data for scripts and you want to like build a complex object this would have been perfect and stuff like that so um goodbye uh backslash and yeah right casey um and then i think i have time to talk about destructuring destruction can be such a big topic i will just show it an easy example real quick so if i have an array of numbers i'll make it simple um if i say something like uh if i i can declare new variables based off of the previous array it's destructuring the array live for you so that you can declare it to new ones and so what you would expect out of this is now you have y declared and initialized as uh based off of where what index of that array you're in so this is the z index zero so it would initialize as one and then at z is in index one and so it initializes two um so that's one way to basically break apart an array into um its own variables for you to use uh the same thing the same thing happens with object suits so if you have an object um i ran out of letters um can i have something like this uh you could do cons a comma b and then uh that'd be the same thing as um uh alpha dot a yeah oh so if you were to say const a that would be the same thing as uh alpha dot a and the font b equals so that's the way to break things apart there are like a this isn't the only way to use it too there's so many different ways to do destruction yeah destructuring is a big topic yeah it's a huge topic but this is just a demonstration that it works and um it allows saving it works in the thing and it evaluates properly okay um hi everyone i'm back um okay we had a lot thank you for monitoring both chat everybody and providing space fully we covered a lot i tried to run through as many things as this is something we've all been excited for we've been waiting for this for so long i remember when they first announced this we were like they really are implementing it i never thought servicenow was gonna have an advanced ethnic script and i just didn't well nani expect that this was coming um oh my gosh someone's gonna make a gif of that oh no listen i've got two gifts of me floating around i hope you enjoy um but it's something that we've all been waiting for now a lot of gabby said it best at the very beginning for someone like me who if you were to contact me three four years ago when i was first starting off in this in servicenow world i was learning javascript for the very first time like i knew some other programming languages before but i didn't know a lot of this stuff and the fact that you um are in servicenow exclusively but then you google javascript how do i do this and it comes up with these things that you can't utilize that was that was hard and um in a lot of ways it forced us to grow which is great because innovation comes from necessity like we can the worst part was not knowing whether it wasn't working because you were bad and wrote something wrong or if it wasn't working because of rhino exactly and um yeah like i said like sometime part of me is thankful that i was able to come up with the work around and stuff like that but oh man being able to use the top option the top answer on the stack exchange or stack overflow would be so much easier um but yeah so there's a lot of cool things in there um real quick i want us to run through our drinks we'll talk about some announcements if anybody on the team has any but um uh jared do you want to rate your drink because at the end of every episode if you don't know we rate our drinks based off of a five-point scale yeah absolutely the birch beer from boulder um i'm not a root beer satsaparilla aficionado so i don't know what it's supposed to taste like but it was really nice i'm going to give it a i'm going to give it a 3.5 a new bread you do this every time i'm the gears are turning my front yard right now which is like from where i'm at so i've been trying to stay muted as much as possible they always do it while i'm live on a zoom or live streaming that was very long i'm doing a new belgium 1554. i knew that was gonna happen at some point uh i'm gonna give it let's say a 3.75 it was fine it wasn't great wow a 375 for a new belgium is pretty pretty low they're good brewery usually uh my uh eagle rare is is my favorite so it's a five bias my goosey passion fruit is a 2.5 it was pretty good drinkable so that's great oh and me um i had a star wars nova single malt whiskey it was um hold up let me chug oh actually it seems better when i do that that will upgrade it a little bit to like a 3.75 it's not the best whiskey i've had but um if you want one of those like those heart goes down hard kind of whiskey's not a good one um but yeah if you like it to hurt you highly recommend servicenow uh scripting right now um welcome to javascript no um so uh again this is i want to thank jared brad andrew and gabby for joining me this episode it's always a delight to have you on with us uh reminder for everybody brad point at it real quick we are at the beginning of our tokyo release so if you haven't heard yet um servicenow has released its uh tokyo release go ahead and go to devlink.sn tokyo to see all the content that we as the developer program have planned um for the next four months regarding tokyo so uh we have a lot of things from podcasts live shows demos blog posts all that all the scripts that i was going running through today i'll make write a blog post over the weekend and post it up so people can refer that refer to that too um but tokyo's here come and hang out and watch us every friday and most tuesdays uh for different shows uh right now we have a build with aes challenge which is what gabby keeps referring to for her video um check it out at devlin.sn build with aes and you can get a free developer t-shirt so check that out um get some service now swag uh for everything else go to developer.servicenow.com to see what we're all about uh don't forget to like and subscribe smash that like and subscribe ring the bell subscribe for more videos we were told we need to say this every episode um i'm getting really warm in red so i'm going to go ahead and say thank you everybody for joining us um it was a great show spam the chat i'll put it on the screen uh thanks have a great weekend love y'all bye i don't love you oh that was on air oh no i got what [Music] foreign

View original source

https://www.youtube.com/watch?v=_CAvRYQQKbs