![]() We can hold detailed information about a thing, such as a pet or customer or blog post, in a set of string, number, and date variables. Or post, and I actually mean a social media post here, but close enough.įigure 3.What about data that represent things in our application? Things like those shown in Figure 3: petNames = Object Data Type (Custom Data Type) With arrays, the user can have an almost limitless number of items, such as names, because we can keep appending to the array. Recall that strings must be enclosed in quotation marks. In some programming languages, including C#, TypeScript, JavaScript, and Python, arrays are defined with square brackets: and each value in the array is separated with commas. ![]() The data items in an array are often of the same type, so you may have an array of numbers, of strings, or of dates. You can think of an array as a list of items. ![]() An array is a collection or set of data items. Using separate string variables to hold multiple items.īut we'd then have to limit how many pets we could allow based on how many variables we'd defined.Īrrays solve this problem. We could hold each name in a separate variable like shown in Figure 1. Let's say we add a feature to our website or app so the user can provide the name of each of their pets. PageTitle = 42 // Variable type is now a number Array (List) Data TypeĪnother important data type in programming is an array, which in some programming languages is called a list. pageTitle = 'Pet List' // Variable type is a string So the type dynamically changes based on the currently assigned value. That type can change if you put a different type of data into that variable. ![]() With "dynamically typed" languages such as JavaScript and Python, the data type defines the kind of data currently assigned to that variable. Can't put a number into a string variable pageTitle = 'Pet List' // Variable is a string. You'll see an error if you try to put the wrong type of data into a variable. correctGuess = trueįor programming languages that are considered to be "strongly typed", such as C# and TypeScript, the data type defines the kind of data that can be assigned to that variable. In a number guessing game, the user's guess was either correct or it wasn't. usersBirthday = April 14, 2001īoolean: we use this for data that only has the value true or false. usersName = "Jack Harkness"ĭate: we use this for data that is a date or time, such as a birthday. Notice that the text inside of the quotes can include spaces and other special characters. In most programming languages, strings require quotes. For example, a name or address or message. String: we use this for any data that is text. If we were building a number guessing game, we would hold the guessed number in a numeric data type, like this: usersGuess = 3 In some programming languages, there are multiple data types for numbers, depending on whether the number is an integer, decimal, or currency, for example. Numbers: we use this for any data that is numeric or should be worked with as a number for addition or other math operations. The most common basic data types available in most programming languages include:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |