Show List

JavaScript Variables and Data Types

Variables in JavaScript are containers for storing values, such as numbers, strings, or objects. Variables are declared using the var, let, or const keyword.
var x;
x = 10;
let y = 20;
const z = 30;

In the above examples, var x declares a variable x, let y = 20 declares a variable y and assigns a value of 20 to it, and const z = 30 declares a constant variable z with a value of 30.

JavaScript has several data types, including:

  1. Number: Used to represent numeric values, including integers and floating-point numbers.
let num = 10;
  1. String: Used to represent text, denoted by either single or double quotes.
let str = "Hello World";
  1. Boolean: Used to represent true or false values.
let flag = true;
  1. Undefined: A value that has not been assigned to a variable.
let name;
console.log(name); // undefined
  1. Null: A value that explicitly represents the absence of a value.
let person = null;
  1. Object: A complex data type used to store collections of data and functions.
let obj = { name: "John", age: 30 };
  1. Array: An ordered list of values, denoted by square brackets [].
let arr = [1, 2, 3, 4];

    Leave a Comment


  • captcha text