Master AI & Build your First Coding Portfolio with SkillReactor | Sign Up Now

2 Variables Data Types

3 Data Types

Data types are essential in programming as they determine the nature of data stored and manipulated within a program. In JavaScript, variables can hold values of different types.

For example:

var x = 19 + "Henry";

In this case, x is assigned the value "19Henry". JavaScript performs type conversion, concatenating the string "Henry" with the number 19.

In contrast:

var x = 19 + 20;

Here, x is assigned the value 39, as JavaScript correctly performs arithmetic addition with two numbers.

All programming languages support several main data types:

  • Numbers: Represent integers and floating-point numbers.
  • Boolean: Represents truth values, true or false.
  • Strings: Represents sequences of characters for text.

Understanding data types is crucial as they govern how data is handled within a program, ensuring accurate processing and manipulation.

JavaScript Data Types

In JavaScript, we have numbers, booleans, and strings. JavaScript is a dynamically-typed language, meaning variables are not bound to a specific data type and can hold values of any type.

For example:

let x = 90; // Number
let floatValue = 20.38; // Number
let text = "This is a string"; // String
let hasPhone = true; // Boolean