
JavaScript is a scripting language that runs in web browsers and is used to add dynamic functionality to web pages.
Since ES6 (ECMAScript 2015), JavaScript has introduced many new features, making programming more powerful and efficient.
To execute a JavaScript file in a Node.js environment, use the following command in the terminal:
node index.js
index.js file must exist in the current directory.| Keyword | Scope | Redeclaration | Reassignment |
|---|---|---|---|
var | Function or global | Yes | Yes |
let | Block | No | Yes |
const | Block | No | No |
var x = 10;
var x = 20; // Allowed
x = 30; // Allowed
let y = 10;
y = 30; // Allowed
const z = 10;
// z = 20; // Error: Cannot reassign
;): Optional but recommended for clarity.// Single-line comment
let x = 10; // Variable declaration
/*
Multi-line comment
Declaring and initializing variable y.
*/
let y = 20;
console.log("Hello, World!"); // Outputs a string
let a = 5;
let b = 10;
console.log(a + b); // 15
JavaScript variables and functions have different levels of accessibility:
{} when using let and const.Functions in JavaScript are first-class objects:
const sayHello = function() {
console.log("Hello!");
};
function executeFunction(func) {
func();
}
executeFunction(sayHello); // "Hello!"
Hoisting refers to JavaScript moving variable and function declarations to the top of their scope.
console.log(x); // undefined
var x = 5;
console.log(y); // Error: Cannot access 'y' before initialization
let y = 10;
function sayHello() {
console.log("Hello!");
}
sayHello(); // "Hello!"
var variables are hoisted and initialized as undefined.let and const are hoisted but not initialized (Temporal Dead Zone).let num = 42; // Number
let name = "Alice"; // String
let isActive = true; // Boolean
let value; // undefined
let empty = null; // Null
let sym = Symbol("id"); // Symbol
let bigNumber = 123456789012345678901234567890n; // BigInt
let person = { name: "Alice", age: 25 }; // Object
let numbers = [1, 2, 3]; // Array
console.log(5 + 3); // 8
console.log(10 - 4); // 6
console.log(6 * 7); // 42
console.log(10 / 2); // 5
console.log(10 % 3); // 1
console.log(2 ** 3); // 8
console.log(5 == "5"); // true (loose equality)
console.log(5 === "5"); // false (strict equality)
console.log(5 != "5"); // false (loose inequality)
console.log(5 !== "5"); // true (strict inequality)
console.log(10 > 5); // true
console.log(5 <= 5); // true
console.log(true && false); // false (AND)
console.log(true || false); // true (OR)
console.log(!true); // false (NOT)
let age = 18;
let status = (age >= 18) ? "Adult" : "Minor";
console.log(status); // Adult
console.log(typeof 42); // "number"
console.log(typeof "hello"); // "string"
let arr = [];
console.log(arr instanceof Array); // true
JavaScript is a versatile language used in both front-end and back-end development.
Understanding the fundamentals is essential for writing efficient and maintainable code.
Great! Many useful features of the program bring the best exploitation. Build and develop the program to practice application soccer random skills. Follow the article topics to improve professional skills.