#3 DATA TYPE CONVERSION AND SPECIAL CHARACTERS | SERVICENOW JAVASCRIPT TUTORIAL | LEARN JAVASCRIPT
Hello friends welcome back to my YouTube channel basico service now learning so this is the third video of servicenote JavaScript tutorial in this video we are going to explore data type conversion and special characters earlier we have covered these three topics and in this video we are going to cover these two topics Okay so friends let's talk about data type conversion this is a very small topic but a useful one so as the name says data type conversion which says that if the data type of any variable is integer or number we can convert the same to string if there is a string we can convert the same to our integer even though we can also convert a string to a float so let's see practically that how we can convert the same there is a very small syntax which we have to use to convert it the syntax is also mentioned in this slide see here that is variable name we have to give who we want to convert and then we have to call to string function right even though if we have to convert a string to integer we can use percent and then we have to use the variable name the variable which we want to convert into a integer okay the same for a float one so let's see it practically so let's move to servicenow personal development instance okay so as I have said for scripting we will be using a background script right so type background over here let's open it in new tab okay so what we have to do we have to do a data type conversion right and what we are going to do we are converting integer to its string first so conversion of integer to string okay so let's declare a variable first let's say variable X equals to 15. so where we have create a variable that is of number right let's create another variable that is variable y okay so let's convert the X into a string and store the data into a variable y so how we can do that X that is variable name as I have mentioned the slide see here the variable name and then to string okay so variable name dot two string function here in that way we can converting this x 15 into a string value so how we can see that Y is string or not so we have to use type of Syntax for the same type of Y okay so this basically telling us what is the type of Y so let's print the same and see what is the type of Y that is g s dot info here and semicolon let's run it see type of Y is string so earlier it was X we converted that X into a string and stored into a y so now y y is a string okay if we are printing y then what will be the answer GS dot info y let's say so see it is displaying as a 15 but it's a string value okay now let's convert a string to a integer integer so how we can do it let's say where uh give any variable name let's say string value I am giving a name let's say Java Script okay this is a string value because this is in double quote or the value which is in single quote or double quote is set to be a string right while declaring a variable so let's create another variable that is where num number value let's convert the string to integer that is parse int then we have to give a variable name here I have to give a variable name over here see here okay now let's see a type of this number all this variable what is it is so I am saying GS dot info here I am just seeing a type of okay copy the type of type of which this variable means we are seeing that we are converting this string to a integer and what is the type of this particular variable okay let's see here let me comment this first because I need to see that output only right non script see it's a number okay but here it is not a number this is particular text only right let's see what exactly the output is if I am printing this particular variable only then it will be displaying as Nan I believe because it's a num not a number right so it will be displaying as a nan over here just a second number value let's print see Nan and N is basically not a number means we have converted it into one number but when we want to display the value that particular variable contains then it is displaying as Nan because it is basically a text right let's say if I am giving a 20 over here okay then basically it will be converting it to a particular integer okay this is a string because it is basically in double quotes or either it is in single code then it is a string right but after doing this if we are running the script C 20 means if we have to convert the string to a number we can see that it will contain a number value within a code otherwise it will be displaying us Nan that is not a number okay the same you would do for a float okay you can try that by yourself in case if you have any doubt you can feel free to comment I will provide you particular solution of it okay so let's see that how it is useful for us and how we can use it so let me give you a practical example that how we can use it okay so let's remove all this code first okay so let's say where x equals to 15. okay another variable variable y equals to C 15 okay this is basically a number value this is basically a string value okay let me give you one example if x equals equals to y then print this otherwise else print this okay so let's what I want to print over here GS dot info if x equals to equals to Y print the values are same okay and here if g s dot info the values are not same okay if I am saying x equals to equals to Y what it will be giving me to me see the value are same basically x equals to 15 y equals to 15 and it is comparing that okay but this is not an answer right because X is a numerical value here Y is a string value and both are totally different but basically this is giving me an answer that value are same means it is basically executing this particular syntax right I mean the semicolon over here just apply it again okay so this is giving me this answer which is wrong right so if I am putting a 3 equals 2 over here then what will be the answer the values are not same why because it is a strict equality comparison operator which is basically comparing comparising the type of the variable also it is not just comparing the values it is also comparing the type of the values so let me store this value Y in a specific variable variable that is that where I am converting this value Y into a number the converting into a number how I can do that pass end and the variable name right the variable is y and I am converting the same to y okay and I am using this Z over here see again run the script see the values are same now it is giving me I output the value you are saying why because we have converted this value into integer so now this strict equality comparison operator is saying that the type of these two variables are also same including with the values okay let's see if I am saying 16 over here right now the values will be different because Z will be containing the value that is 16 for example GS dot info let's shape in the value Z okay so here it is giving me answer 16 and the values are nets not same because X is 15 and Z basically is a 16. both the values are different even though the type is same so I believe now you have understanding that why we need this data type conversion right we can convert the numerical value which was earlier declared as a string we can use that value and convert that into in same as for the string also that if we need some integer as a string we can convert the data type in between the code okay so this is basically very small topic but once we are writing the core it valued a lot sometimes okay so now I believe you have understanding of data type conversion in case if you have any question related to the same feel free to comment in the comment box below so now let's move to another topic that is special characters so what is this special characters and why we need it so friends this is also a very small topic but sometimes when we are displaying some text message into a form or into a message right then we need it so for example if we have to display two lines okay then this particular special characters comes into picture when we have to place a double quote then this particular topics comes into picture so once I will be giving you a particular example definitely you will be having a better idea of it okay so let's move to service development instance I will be giving you an example in a client-side script for a better understanding so friends go here type client script open this client script click on new okay so let's say give any name whatever you like special character demo but the name should be purposeful right table select incident because I will be demonstrating in the incident form then type I want to display a message on load so what I basically want to do I want to display this message okay this is one line this is another line how I can display the same let me give you example of it so let me copy this message okay so here let's see I want to display alert when the incident form opens so as I copied this message I place this message over here okay so let me also remove this first okay this is a message let's save it so let's open the incident form first uh incident see once I open the student form alert message please attach your manager's approval email on that see this is a single line over here right I want this for any query please reach out that will come in another line okay how I can achieve the same let's see see if I press enter hover here like this see it is displaying me an error that I cannot do this how I can make it in such a way that it will display separately in two lines in that way the special characters comes into picture Okay so as I have displayed in the slide for a new line what I have to use I have to use backslash n so here while in a message I can type backslash n see here okay let's save the code and let's again reload the form see two different lines okay in this way it is useful the another way is there is a requirement where they say keep this manager in double quote managers approval and double code see if I put double code over here see in that way it is giving me a error means I cannot do this while writing this particular message so what I have to do for the same I have to put a specific syntax over there for a double code that is backslash double quote so here I have to give backslash double coat and here I also have to give backslash double quote okay here in that way let's save it and let's refresh the window again see manages approvals comes under double quotes in this way we are putting this double quotes special characters within a message okay apart from this we also have some other things you can try by yourself and one more important thing that we have placed this uh this in this particular client script we can also run the same here in the background script if you want see here but here alert will not work what you have to give GS dot info or GS dot print see okay so the way is same you can implement the same in the server side script even though you can also use the same in the client-side script the only thing what you have to remember is this particular thing for new line you have to use backslash n for tab you have to use backslasht for backslash you have to use this double uh I can say backslash right for single code you can use this even though single code is not required because a browser automatically recognize the same you can give the single code directly there is no need to do this but for for sure for the double code you have to give backslash double code just to implement as I have displayed in the demonstration then otherwise it will be throwing a error right so friends I have put all this content to my web page that is mentioned over here I will post this link in the comment box you can directly get that content over there so this is all for this video I hope this video is helpful for you and have gave a basic understanding of data type conversion and special characters right so friends if this video is helpful then please do like this video and still you have not subscribed my Channel please do subscribe my YouTube channel thank you friends have a nice day bye bye
https://www.youtube.com/watch?v=bQuOkmsCQhM