digital dreamscapes - by somnath pan
Welcome to our JavaScript Basics tutorial! In this tutorial, we'll cover the fundamental JavaScript concepts and syntax to program your web page.
This JavaScript tutorial assumes that you have a basic knowledge and understanding of HTML and CSS, if you're new to HTML and CSS, consider exploring our html-basics tutorial and css-basics tutorial, before proceeding to this JavaScript tutorial
JavaScript is a programming language used to add interactivity to web pages.
Use the let
keyword to declare variables and assign data types.
let name = 'John Doe';
let age = 30;
Use if
and else
statements to make decisions in your code.
if (age > 18) {
console.log('You are an adult');
} else {
console.log('You are a minor');
}
Use functions to reuse code and perform tasks.
function greet(name) {
console.log(`Hello, ${name}!`);
}
greet('John Doe');
Use for
loops to iterate over arrays and objects.
for (let i = 0; i < 5; i++) {
console.log(i);
}
Use event listeners to respond to user interactions.
document.getElementById('button')
.addEventListener('click', function() {
console.log('Button clicked!');
});
Congratulations! You've learned the basic JavaScript concepts and syntax. Practice building your own web page using this tutorial as a reference. In the next tutorial, we'll explore JavaScript objects and arrays.
function
keyword to declare a function.null
represents an intentional absence of value, while undefined
represents an uninitialized or absent value.