Content types in variables


Published on 28 March 2022


Content types in variables

What type of content can we have in the variables

Variables in javascript can have the following content types:

  • Numbers
    • The content of a variable is of numeric type and operations can be done with these numbers:
      • Sum: console.log(3+3)
      • Subtraction: console.log(3-3)
      • Multiplication: console.log(3*3)
      • Division: console.log(3/3)
      • Less than: console.log(1<3)
      • Greater than: console.log(4>3)
      • Greater than or equal: console.log(3 >= 3)
      • Less than or equal: console.log(3 <= 3)
      • Same in data type and number: console.log(3 === 3)
      • Not the same in type and number: console.log(3 === '3')
      • Same in number: console.log(3 == 3)
      • Not the same: console.log(30 != 20)

 

  • String
    • Content of a variable that consists of the union of characters or text. 

The operations that can be done with a string are:

Join string content using the + symbol, this action is called concatenating text.

For example: 'hello'+'world'

  • Boolean
    • It is a data type that only admits true or false values, and it is very useful to check information within any javascript code. 

For example, to check that a user can be logged in, which can be true or false.
We check if one number is greater than another:

console.log(Boolean(5 > 2)); //returns true
console.log(Boolean(3.14)); //returns true
console.log(Boolean('2' === 2)); //returns false
console.log(Boolean('2' == 2)); // returns true
console.log(Boolean(NaN)); // return false
console.log(Boolean(-1)); // Returns false when negative
console.log(Boolean(0)); // Returns false since it is not positive
  • Undefined
    • The content type for a variable is undefined, that is, it is an undefined variable or has no value.
      • Undefined variable example:
        console.log(name_var);
        var name_var = 5;
        This variable is undefined since first you want to show on the screen a variable that has not been defined, so it will not have any value.
  • Null
    • The content of a variable is defined and its value is null.
      • Undefined variable example:
        var name_var = null;
        console.log(name_var);

Previous Chapter - Next Chapter


Tips on SEO and Online Business

Next Articles

Previous Articles