JavaScript is a programming language used to add interactivity to web pages. It's one of the core technologies of the web, alongside HTML and CSS. Below are some key JavaScript concepts every beginner should learn.
The typeof
operator is used to determine the type of a value. For example, typeof undefined
returns 'undefined'
.
console.log(typeof undefined); // 'undefined'
const
is used to declare variables that cannot be reassigned. It provides block scope and is useful for fixed values.
const pi = 3.14;
// pi = 3.14159; // ❌ This will cause an error
document.getElementById()
is used to access an HTML element by its ID. If no element is found, it returns null
.
let element = document.getElementById('demo');
console.log(element); // null if no element with ID "demo"
The concat()
method joins two or more strings. It doesn't change the original strings.
let a = "Hello, ";
let b = "world!";
let result = a.concat(b); // "Hello, world!"
Comments are used to explain code and are ignored during execution. In JavaScript, single-line comments start with //
.
// This is a comment
let x = 5; // This is also a comment