We’ve all stumbled on a web page that just doesn’t work. You know the type: the links aren’t clickable, the scrolling is all over the place, and sometimes...they automatically play music. (The worst.)
So let’s dive in!
|Number||Deals with any number, including decimals. You can also do operations (like multiplication, division, etc.) with this data type.|
|String||A string of characters surrounded by single or double quotes.|
|Boolean||Sets a true/false (or yes/no) value.|
|Null||Indicates the intentional absence of a value. Basically means “nothing,” “empty,” or “value unknown.”|
|Undefined||Also indicates the absence of a value. Unlike “null,” “undefined” is usually used when a variable is declared but a value is unassigned.|
|Symbols||Unique identifiers for objects.|
|Object||Collections of related data. Unlike other data types, which can only contain a single thing, objects store collections of data.|
Why Are Data Types Important?
The other reason data types are important is because they dictate what you can do with the data you provide—and whether that data will work or not. For example, if you try to assign a value to a “null” data type, it won’t work because null indicates an empty value! Likewise, there are some data types that only do one thing, like the boolean data type, while others can work with collections of data.
In order to use the TypeOf command, you would write it like you would any operation that uses a single value (also known as a unary operator). That means the script would look like this:
If (typeof object === ‘undefined’)
The TypeOf function is an important tool when dealing with complex code. It allows a programmer to quickly check a variable’s data type—or whether it’s “undefined” or “null”—without going through the code line by line! Additionally, the TypeOf function can also check whether an operand is an object or not.
Depending on the output of the TypeOf function, a programmer can adjust their previous code or quickly pick up where they left off on a project. In other words, the TypeOf function is a quick way to check data to make sure that a script will work.
What Are the Possible Outputs of the TypeOf Function?
|Boolean (true or false)||“boolean”|
|host objects||Dependent on implementation|
If you’re interested in coding, it might be worth considering a computer science major. But how do you know if computer science is really right for you? Here are five key factors to consider when choosing your major.
If you do want to go into computer science, it’s important to get into a good college. One of the best ways to do that is to make sure you’re taking the right courses in high school. Check out this expert guide to the classes you should—and shouldn’t—take before you start your college applications.
You might have heard that AP classes look good on your college application. If you’re not sure what AP classes are or how they affect your college admissions chances, take a look at this AP overview.Have friends who also need help with test prep? Share this article!
Ashley Sufflé Robinson has a Ph.D. in 19th Century English Literature. As a content writer for PrepScholar, Ashley is passionate about giving college-bound students the in-depth information they need to get into the school of their dreams.