DEV Community

Erasmus Kotoka
Erasmus Kotoka

Posted on

" hello what are we opening with this JavaScript Fundamentals πŸ˜‰ ? 🌟 **Variables and Data Types in JavaScript** 🌟

JavaScript is a versatile programming language used to create dynamic and interactive web pages. Understanding variables and data types is fundamental to writing effective JavaScript code.

  1. Variables:

In JavaScript, variables are used to store and manipulate data. They act as containers for values that can be changed or updated throughout the execution of a program. Here's how you declare a variable:


let greeting = "Hello, World!";

Enter fullscreen mode Exit fullscreen mode

The let keyword is used to declare a variable named greeting and assign it the value "Hello, World!". Variables in JavaScript can also be declared using var and const depending on the scope and mutability requirements.

  1. Data Types:

JavaScript supports various data types, including:

  • Primitive Data Types: These are the basic building blocks of JavaScript and include:

    • String: Represents text data enclosed within quotes.
    • Number: Represents numeric values, both integers and decimals.
    • Boolean: Represents true or false values.
    • Null: Represents the intentional absence of any value.
    • Undefined: Represents a variable that has been declared but not assigned a value.

let name = "John";

let age = 30;

let isStudent = true;

let data = null;

let status;

Enter fullscreen mode Exit fullscreen mode
  • Non-Primitive Data Types: These are more complex data types and include:

    • Object: Represents a collection of key-value pairs.
    • Array: Represents a list of elements enclosed within square brackets.
    • Function: Represents reusable blocks of code.

let person = { name: "John", age: 30 };

let colors = ["Red", "Green", "Blue"];

function greet(name) {

 return "Hello, " + name + "!";

}

Enter fullscreen mode Exit fullscreen mode

Understanding these data types and how to use variables effectively is essential for building robust JavaScript applications.

Let's keep learning and exploring the fascinating world of JavaScript together! πŸ’»πŸš€

KEEPmoving ✈

Top comments (2)

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

You've missed BigInt and Symbol from the primitive data types πŸ‘

Collapse
 
erasmuskotoka profile image
Erasmus Kotoka

Okay thanks. Seen