What is JavaScript?
JavaScript is the core language that is used by ServiceNow developers to work and manage the ServiceNow instance. The programming language is the base for the scripting we learned. Before writing scripts in ServiceNow, it is important to know what language they are written in.
In this topic, we will focus on what JavaScript is, how it fits into ServiceNow, and the data it uses, including variables and data types.
What is JavaScript?
JavaScript is a cross-platform, interpreted scripting language standardized as ECMAScript that uses an interpreter and just-in-time compiler for ServiceNow developers. It is used to create static and dynamic web pages.
- The interpreter translates the code line by line.
- The compiler converts the code to machine code at runtime.
Why should a developer learn JavaScript?
It is important to learn JavaScript for ServiceNow developers because:
- Glide APIs are created in ServiceNow and are called using JavaScript.
- To validate input and process records using conditions, loops, and functions.
- It improves performance and makes the instance easier to maintain.
Variables
JavaScript variables are containers for temporary memory storage during the script run. They are labelled boxes where you put the value and retrieve it using the label name. var, let, and const are JavaScript keywords used to declare variables and assign values.
There are two types of Variable Scopes:
- Global variables: Declaring a variable outside the function makes it a global variable. They can be accessed anywhere in the program.
- Local variables: Declaring a variable inside the function makes it a local variable. They are accessed inside that function only.
Data Types
A data type defines what kind of data is assigned to a variable. JavaScript provides a list of data types that hold different kinds of values. JavaScript is a dynamically typed language, which means you don’t need to specify a variable’s type because the JS engine identifies it dynamically.
JavaScript primitive data types
These data types hold single, simple values.
| Type | What it holds |
|---|---|
| String | Text |
| Number | Integers and decimals |
| Boolean | true or false |
| Undefined | A variable declared but not assigned |
| Null | An intentional empty value |
JavaScript non-primitive data types
Non-primitive types have collections of values or more complex structures.
- Object: It is a real entity and can be created by using the “new” Keyword.
For ex: var car = { brand: “Toyota”, year: 2024 };
- Array: A collection of elements.
For ex: var y=[1,2,3,4,”apple”]
- Regular Expression: Patterns used to match character combinations in strings.
For ex: var regex= /ab+c/;
What’s Next?
In the next topic, we’ll focus on how String Functions work in JavaScript and what Conditional and Looping Control Statements are in ServiceNow JavaScript.
Next TopicNeed more support?
Get a head start with our FREE study notes!
Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.