JavaScript Foundations - Data Types

Image description

Hi everyone!

As a second entry to my JavaScript Foundations, I want to cover something briefly that I learned recently, which is Data Types in JavaScript.

The data types you will find are listed below:

  1. String
  2. Number
  3. Bigint
  4. Boolean
  5. Undefined
  6. Null
  7. Symbol
  8. Object

Let's get some examples for each of these, and hopefully, it will better help you understand a use case for them whilst also increasing your JavaScript knowledge.

1: String

A string holds sentences, words, or letters. A use case for this in JavaScript would be storing a username, address line, or a sentence to reuse.

let sentence = "JavaScript is awesome";
console.log(sentence);

2: Number

Numbers in JavaScript include both integers and floating-point values. They are used for arithmetic operations, counting, and more.

let age = 25;
let price = 99.99;
console.log(age, price);

3: BigInt

BigInt is used for handling numbers larger than the maximum safe integer value in JavaScript (2^53 - 1).

let bigNumber = 9007199254740991n;
console.log(bigNumber);

4: Boolean

A Boolean represents a logical value, either true or false. This is commonly used in conditions and comparisons.

let isJavaScriptFun = true;
console.log(isJavaScriptFun);

5: Undefined

A variable that has been declared but not assigned a value has the type undefined.

let notAssigned;
console.log(notAssigned); // Output: undefined

6: Null

null represents an intentional absence of any object value.

let emptyValue = null;
console.log(emptyValue);

7: Symbol

A Symbol is a unique and immutable primitive value, often used for object property keys.

let uniqueKey = Symbol("id");
console.log(uniqueKey);

8: Object

Objects are collections of key-value pairs and can store complex data structures.

let user = {
  name: "Alice",
  age: 30,
};
console.log(user);

Conclusion

Understanding these data types is fundamental to working with JavaScript effectively. They help you manage and manipulate data efficiently, setting a strong foundation for programming in JavaScript.

Thanks for reading !!

NullProgrammingFoundationsJavaScriptData Type
Avatar for Roger O'Donnell

Written by Roger O'Donnell

Junior Web Developer

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.