Master Data Types in Wized
Learn the Most Common Data Types Used in App Development with Wized
As you might have figured by now, Wized allows you to work with several data types.
You might have heard us mention some terms such as strings, numbers and arrays.
And if you still don’t know what these are, then this video is going to help you make sense of it.
We’ll talk about each of the most common types of data that you can use in your app.
You'll learn what are:
Strings
Strings are collections of alphanumeric characters and symbols.
This is how we’re going to store letters and words, things like names, email addresses, and URLs. If you simply write a word into a data field, Wized will already know that this is a string.
However, if we are working within a logic component—inside of these squiggly brackets—we need to wrap text inside of quotation marks.
This is because logic components consist of simple JavaScript. And in JavaScript, a string needs to be wrapped inside of single or double quotation marks to be interpreted by the browser as a string.
The cool part is that within a logic component, you can combine multiple strings by adding a plus sign in between.
Note that you can also combine logic components with regular text like this. Either way will work. You can always see a preview of the output below.
Numbers
Numbers are just what they sound like.
They’re numbers, including both integers like 1, 2, or 3, and decimals like 3.14.
You can use numbers to perform mathematical operations, but they may also just be a number like a count of how many people you have in your team.
If you want to do math in Wized, you can simply use arithmetic operators. Like so */+-
. You can even use the plus sign to combine a string and a number.
Booleans
Booleans can only have two values.
True and false.
They represent all data that only has two states, like a checkbox. Most commonly, you’ll use Booleans for conditional logic.
For example, we can write a simple if-else statement like this:
false ? “Booleans are awesome” : “Booleans suck”
But this example is pretty useless.
Why? Well, because we are manually writing true and false.
This is where truthy and falsy values come in.
Basically, any value can be turned into a Boolean.
For example, if you add a response field to our conditional, and the field does have a value like this one, it will be true. Because there is something there.
On the other hand, if that field wasn’t in the request, because we don’t have an error in the response, the condition will evaluate to false. Because there’s nothing there.
We will cover conditionals, truthy and falsy values in much more depth in separate videos. But for now, it’s important to know that Booleans play an essential role when it comes to your app's logic.
Undefined and Null
Undefined means that the variable has been created, but has never been given a value. It is simply nothing because no one has ever added a value to it.
Null is similar to undefined, except it has to be set intentionally.
You could use null if you want to tell the app to do nothing.
For example, let’s say we wanted to display a user’s name if the name was provided. Otherwise, we don’t want to display anything. We can write a simple if-else statement like this:
[r.4.d.name](<http://r.4.d.name>) ? “Hi” + r.4.d.name : null
Of course, you could also use an empty string here to achieve the same thing. But for now, it’s important to know that you know that null exists.
Objects and Arrays
Both objects and arrays are collections, a way to group together multiple points of data into a single bundle.
Objects
Objects consist of key-value pairs.
You can think of keys as a column header in your data table, and the values represent the content that’s inside of the first row.
If you see key-value pairs wrapped with squiggly brackets, know that you’re dealing with an object.
And if this looks like a JSON file that you saw somewhere, this is because JSON files ARE JavaScript objects.
JSON stands for JavaScript object notation.
Now, if you want to access a property of an object, you can do this by writing objectName.property
.
You probably already saw this pattern when selecting a field from a request response.
We have r.4.d[0].name
r is the request object, 4. is a property, and d[0].name are nested objects and properties.
We can use any of the above-mentioned data types inside of objects, and we can EVEN nest objects inside of objects.
Arrays
An array is a collection of comma-separated values, wrapped with these square brackets.
Arrays can also contain any data type, so you can have strings, numbers, Booleans, or you can have an array of objects and an array of arrays.
As you can imagine, this allows for some really complex data structures, which are much more intricate than our simple spreadsheet.
Arrays are most commonly used when we want to render a list of items.
If you need to access an element that’s inside of an array you can simply use the index of the element like so. Just note that indexing always starts at 0.
So if you want to access the first element of the array you would write r.5.d.name[0]. As you probably know by now, if you want to render all of the
elements of an array, you need to loop through the array using a loop component. We'll cover loop components in more detail in another video.
That's it for our overview of data types in Wized. Understanding these data types is crucial for building any app, as they form the building blocks of your app's logic and functionality.
If you have any questions, feel free to reach out to our support team. We're always here to help.