Data Types Numbers, Strings, Booleans, Arrays, JSON Objects
Data types define the kind of values a variable can hold in JavaScript.
Kinds of Data Types:
1. Number: Integers and floating-point values.
let int = 3
let flt = 3.14159
In the platformer game, the use of integers is needed to keep track of the time passed, number of coins collected, and various other tasks.
2. Strings: A sequence of characters enclosed in quotes.
let str = 'hello!'
In the platformer game, strings allow for messages to be displayed during the game, and these messages can help guide the player through the levels.
3. Booleans: Represents true or false, commonly used in logical operations.
let bln1 = true
let bln1 = false
In the game, booleans are used as values for static properties (eg. keyCollected, trashCollected, hasFlag)
4. Arrays: A collection of elements, indexed from 0.
let arr = [1, '2', false, 'hell0']
In the game, we use arrays to store different kinds of values and allows us to access those values at any time.
5. JSON Objects: A structured data format using key-value pairs, useful for API responses and data storage.
let obj = {
name: 'Veera',
age: '14',
birthday: 'N@tM'
}
In the game, object-oriented programming makes the code more organized and accesible in all other files.