Skip to main content
Practice

JavaScript Summary

JavaScript is an essential programming language in web development, often referred to as the brain of web pages.

Let's briefly summarize the core concepts of JavaScript.


1. Variables

Containers for storing data. Stored data can be of various types such as numbers, strings, booleans, objects, etc.

Variable declaration with the let keyword
let name = 'CodeFriends';

2. Functions

Reusable blocks of code that perform specific tasks.

Declare greet function
function greet(userName) {
console.log('Hello, ' + userName + '!');
}

greet('CodeFriends'); // "Hello, CodeFriends!" output

3. Conditional Statements

Execute different code based on certain conditions.

if-else conditional statement
if (name === 'CodeFriends') {
console.log('Hello, CodeFriends!');
} else {
console.log('Hello, Guest!');
}

4. Loops

Repeat a block of code multiple times based on certain conditions.

for loop
for (let i = 0; i < 5; i++) {
console.log(i); // Outputs 0 to 4
}

5. Objects

Collections of related data and/or functionality. These are often referred to as properties (keys).

person object
const person = {
name: 'CodeFriends', // name property, string value
age: 25, // age property, number value
greet: function () { // greet property, function value
console.log('Hello, ' + this.name + '!');
},
};

person.greet(); // "Hello, CodeFriends!" output

6. Events

Interactions on a web page such as button clicks, form submissions, page loads, etc.

Detect button click event
let button = document.querySelector('button');

// Button click event listener
button.addEventListener('click', function () {
alert('You clicked the button!');
});

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.