DEV Community

Chithra Priya
Chithra Priya

Posted on

What I learn JavaScript in Day 1:

JavaScript is one of the most widely-used programming languages for web development. Whether you're creating interactive websites or dynamic applications, understanding JavaScript’s core concepts is essential. In this blog post, we’ll walk through some of the building blocks of JavaScript: data types, variables, return values, functions, parameters, function calls, and concatenation.
**

1. JavaScript Data Types:

JavaScript supports several data types, which define the kind of data a variable can hold. These include:

String – Text enclosed in quotes.
Example: "Hello World"

Number – Numeric values.
Example: 42

Boolean – Represents true or false.

Null – A variable with an explicitly empty value.

Undefined – A variable that has been declared but not assigned.

2. Variables in Javascript:

JavaScript provides three ways to declare variables:

let name = "Alice"; // Preferred for variables that may change
const age = 30; // Constant, cannot be reassigned
var isStudent = true; // Older usage, generally avoided

Tip: Use let and const for clean, modern JavaScript.

3. Functions in Javascript:

Set of instructions that you write once and can use again and again.

Example:

function sayHello() {
console.log("Hello!");
}

function tells JavaScript you're creating a function.

sayHello is the name of the function.

The {} holds the code that runs when the function is called.
Enter fullscreen mode Exit fullscreen mode

To use (or "call") the function:

sayHello(); // This will print "Hello!" in the console

4. Parameters in Javascript:

A parameter in JavaScript is like a placeholder or a variable you use in a function to accept input values.
Example:

function greet(name) {
console.log("Hello, " + name + "!");
}

name is a parameter.

It lets the function greet different people.

When you call the function, you give it a value (called an argument):
A function is a reusable block of code. You can pass values to it using parameters.

function greet(name) {
return "Hello, " + name;
}

Here:

greet is the function name.

name is the parameter.

The function returns a greeting string.

5. Calling a Function

To run or “call” a function, use its name followed by parentheses and pass any required arguments.

let message = greet("Alice");
console.log(message); // Output: Hello, Alice

6. The return Statement

The return keyword sends a result back from the function.

function add(a, b) {
return a + b;
}

let result = add(5, 10); // result = 15

If no return is used, the function returns undefined.

7. String Concatenation

Concatenation means combining strings. You can use the + operator or template literals:

let firstName = "John";
let lastName = "Doe";

// Using + operator
let fullName = firstName + " " + lastName;

Top comments (0)