Data Types

JavaScript Data Types

🙋 Need help? Ask an expert now!

JavaScript is weakly typed language. It allows most operations on any values without regards to their data type. Values have data types, but the variables themselves don't. Variables can hold any data type as shown in the sample code below. All variables are declared with the keywords var, let or const.

As shown in the sample code above, there are many data types and ways to declare a variable. The variable count holds an integer data type in the first line, but is assigned to a string data type in the second line. This is allowed in JavaScript as all variables can hold any data type. Other data types including float (basically int but with decimals), as well as boolean (either true of false). The const keyword is only used in when we want to create a constant that will not change in the program. This is the reason why MAX_COUNT = 0; is commented in the program. Removing the comments will cause an error as the value of the constant MAX_COUNT cannot be changed after it is declared

Edit Me on GitHub!

Application Question

Which of the following statements assigns the integer 2 to the variable varOne ? (Assume varOne has already been declared)