JavaScript Data Types

  • You may have noticed in the first two sections that we declare new variables in the same way no matter what we set them equal to, by using the let keyword and giving the variable a name.
  • JavaScript has dynamic variables. This is what allows us to declare all variables in the same way, and what allows us to reset a variable that may have stored a number before, to storing a string of text.
  • Without realizing, though, you have been following syntax conventions for different data types.
  • When we set a new variable equal to a number, we simply set it equal to that number. But when we set a new variable equal to text, we set it equal to the text within quotation marks.
  • It is important to become familiar with the different data types, and when and how to use them.

    1. Numbers

  • Other programming languages typically specify the use between variables that store integers, which are whole numbers, and variables that store doubles, which are numbers with fractions or decimals.

  • JavaScript has dynamic variables, however, so there is no need to specify whether a variable is storing an integer or decimal/double.

  • To create a variable that stores a numeric value, we simply declare a new variable to that value. Examples:

    let myNumber = 45678930;
    let shoppingBill = 45.89;
    let myAge = 20;
    let numberOfPetsIOwn = 4;
    
JavaScript Data Types You may have noticed in the first two sections that we declare new variables in the same way no matter what we set them equal to, by using the let keyword and giving the variable a name. JavaScript has dynamic variables. This is what allows us to declare all variables in the same way, and what allows us to reset a variable that may have stored a number before, to storing a string of text. Without realizing, though, you have been following syntax conventions for different data types. When we set a new variable equal to a number, we simply set it equal to that number. But when we set a new variable equal to text, we set it equal to the text within quotation marks. It is important to become familiar with the different data types, and when and how to use them. 1. Numbers Other programming languages typically specify the use between variables that store integers, which are whole numbers, and variables that store doubles, which are numbers with fractions or decimals. JavaScript has dynamic variables, however, so there is no need to specify whether a variable is storing an integer or decimal/double. To create a variable that stores a numeric value, we simply declare a new variable to that value. Examples: let myNumber = 45678930; let shoppingBill = 45.89; let myAge = 20; let numberOfPetsIOwn = 4;