JavaScript is a popular programming language widely used for building dynamic and interactive websites. Known for its ease of use and flexibility, it is favored by developers. This article compiles commonly used JavaScript terms to help beginners and experienced developers quickly grasp the fundamentals.
Primitive Types
JavaScript has six primitive data types:
Primitive values have no properties or methods, are immutable, and comparisons are made by value rather than reference.
Object Types
Besides primitive types, JavaScript includes object types. Objects are collections of key-value pairs called properties. Properties can be accessed with dot notation or bracket notation. Arrays and functions are also objects in JavaScript.
Operators are special symbols used to perform operations on operands. JavaScript includes several operator types:
Arithmetic Operators
var x = 5;
var y = 10;
console.log(x + y); // Output: 15
console.log(y - x); // Output: 5
console.log(x * y); // Output: 50
console.log(y / x); // Output: 2
Assignment Operators
var x = 5;
x += 10; // Equivalent to x = x + 10
console.log(x); // Output: 15
Comparison Operators
var x = 5;
var y = 10;
console.log(x < y); // Output: true
console.log(x > y); // Output: false
console.log(x == y); // Output: false
console.log(x != y); // Output: true
Functions are blocks of code designed to perform specific tasks. They accept one or more arguments and return values. In JavaScript, functions are objects, meaning they can be assigned to variables, passed as arguments, or returned from other functions.
Function Declaration
function hello(name) {
console.log("Hello, " + name + "!");
}
hello("John"); // Output: Hello, John!
Function Expression
var hello = function(name) {
console.log("Hello, " + name + "!");
};
hello("John"); // Output: Hello, John!
Events are actions or occurrences in a webpage, like clicking a button or scrolling. JavaScript uses events to trigger code execution.
Event Listeners
document.getElementById("myButton").addEventListener("click", function() {
alert("Button clicked!");
});
Event Object
The event object holds details about the event, such as which key was pressed or which mouse button was clicked. It is passed as a parameter to the event handler function.
document.addEventListener("keydown", function(event) {
console.log("Key pressed: " + event.key);
});
This article organizes common JavaScript vocabulary and basic concepts useful for PHP beginners and front-end learners as a reference. Continuous learning and practice are key to mastering JavaScript, and this guide aims to help you get started quickly and improve your skills.