Primitive Data Types
Strings are used to represent text and are defined using quotes. They can be manipulated using various methods, including concatenation and slicing.
To create a string, we must place our text within double quote marks. The word “string” alone is not enough; we must have the actual quotes to indicate that we are creating a string. Once inside the quotes, we can input any alphanumeric character that we wish, including weird special characters, numbers, and letters.
However, we must be cautious when using quote marks within strings as using the same kind of quote mark will end the string prematurely, leaving a lone quote mark outside the string.
Backticks are another method of creating a string that has certain advantages over double quotes and single quotes. For instance, backticks allow us to use the enter key to split a string into multiple lines of code. Thus, if we have a long sentence that we wish to split into two lines, we can do so with backticks but not with double quotes or single quotes.
While developers often use backticks as their default string format, it’s important to note that double quotes and single quotes are equally valid methods of creating a string. Strings are crucial in human communication, as they allow us to store and convey messages and sentences intact, exactly as the user intended.
Booleans represent two values – true and false. They are often used in conditional statements to control the flow of a program.
Null and Undefined
Null and undefined are used to represent the absence of a value. Null is often used to indicate that a variable has no value, while undefined indicates that a variable has been declared but has not been assigned a value.
Symbols are unique and immutable data types that are often used to create objects with unique identifiers.
Object Data Types
Objects are a more complex data type that can store multiple values. They are defined using curly braces and can contain properties and methods.
Arrays are a type of object that can store multiple values in a single variable. They are defined using square brackets and can contain any data type.
Functions are a type of object that can be invoked to perform a specific task. They can be assigned to variables and passed as arguments to other functions.
Dates are a type of object that represents a specific date and time. They can be used to perform calculations and manipulate dates.
Explicit coercion occurs when a programmer manually converts a value from one data type to another. For example, using the “Number()” function to convert a string to a number.