Skip to main content

Posts

JavaScript Events | Click and Mouseover Event - Mouseout and Change Event - Submit and Load Event - Some common JavaScript events

JavaScript Events: JavaScript events are actions or occurrences that happen in the browser, triggered by the user or the browser itself. JavaScript code can respond to these events by executing functions or scripts.  Here are some common JavaScript events: 1. Click Event:    - Occurs when an element is clicked.    javascript    document.getElementById("myButton").addEventListener("click", function() {        // Code to execute when the button is clicked    });     2. Mouseover Event:    - Occurs when the mouse pointer is moved over an element.    javascript    document.getElementById("myElement").addEventListener("mouseover", function() {        // Code to execute when the mouse is over the element    });     JavaScript Events 3. Mouseout Event:    - Occurs when the mouse pointer leaves an element.    javascript  ...

JavaScript Functions | Function Declaration and Expression - Arrow Function - Function Parameters and Return - Basic syntax and usage of JavaScript functions

JavaScript Functions: JavaScript functions are blocks of code designed to perform a specific task. They are defined using the function keyword and can be invoked (called) at any point in a program.  Here is the basic syntax and usage of JavaScript functions: Function Declaration: javascript // Function declaration function greet(name) {   console.log("Hello, " + name + "!"); } // Function invocation greet("John"); // Output: Hello, John! JavaScript Functions In the example above: greet is the function name. (name) is the parameter list. Functions can accept parameters (input). The function body is enclosed in curly braces {} and contains the code to be executed. console.log is a built-in JavaScript function that outputs information to the console. Function Expression: javascript // Function expression var add = function (a, b) {   return a + b; }; // Function invocation var result = add(3, 5); console.log(result); // Output: 8 In this example: add is ...

JavaScript Strings | Creating Strings - Concatenation - Length - Accessing Characters - Methods - Some key points about JavaScript strings

JavaScript Strings: In JavaScript, a string is a sequence of characters that is used to represent text. Strings are a fundamental data type in the language, and JavaScript provides various methods and properties to work with them.  Here are some key points about JavaScript strings: 1. Creating Strings: Strings can be created using single quotes (`'`) or double quotes (`"`). Both forms are equivalent, and you can choose the one that fits your coding style.    javascript    let singleQuoted = 'This is a string.';    let doubleQuoted = "This is also a string."; JavaScript Strings 2. String Concatenation: Strings can be concatenated using the `+` operator.    javascript    let firstName = 'John';    let lastName = 'Doe';    let fullName = firstName + ' ' + lastName; // Result: 'John Doe' 3. String Length: The length of a string can be obtained using the `length` property.    javascript    le...

JavaScript Arrays | my experiences

Introduction to JavaScript Arrays Arrays are a means of creating a collection of values of the same kind by javascript. A type of value means either only strings or only integers or floating point numbers etc. Arrays are used to avoid the problem of creating too many variables. JavaScript Arrays For example, if you want to store the names of 200 employees, for that you do not need to create 200 variables. You can create an array in which 200 names can be stored. Doing this saves the time of programmers. Array Elements Indexing in JavaScript Every element of an array can be uniquely identified. Stores the array values ​​by indexing. But always remember that the array starts with index zero. So in the example mentioned above, the first name will be at 0 index and finally the name will be at 199 index. You can access any value of an array by the name of the array and its index number. You should also always remember that arrays are objects in JavaScript. That's why you...

JavaScript Control Statements | if - if-else if-else Statement - switch Statement in JavaScript

JavaScript Control Statements: JavaScript control statements are used to manage the flow of a program by making decisions and repeating actions based on conditions. The primary control statements in JavaScript include: JavaScript Control Statements 1. if Statement:    - The `if` statement is used to execute a block of code if a specified condition evaluates to true.    javascript    if (condition) {      // Code to be executed if the condition is true    } 2. if-else Statement:    - The `if-else` statement is used to execute one block of code if a condition is true and another block if the condition is false.    javascript    if (condition) {      // Code to be executed if the condition is true    } else {      // Code to be executed if the condition is false    } All Computer Buttons and Ports 3. if-else if-else Statement:    - This stat...

JavaScript Operators | Arithmetic - Assignment - Comparison - Logical - Unary - Conditional and Bitwise Operators - Types of operators in JavaScript

JavaScript Operators: JavaScript operators are symbols used to perform operations on variables and values. They allow you to manipulate data and perform calculations.  Here are the main types of operators in JavaScript: 1. Arithmetic Operators:    - `+` (Addition): Adds two operands.    - `-` (Subtraction): Subtracts the right operand from the left operand.    - `*` (Multiplication): Multiplies two operands.    - `/` (Division): Divides the left operand by the right operand.    - `%` (Modulus): Returns the remainder when the left operand is divided by the right operand.    - `` (Exponentiation): Raises the left operand to the power of the right operand.    javascript    let a = 5;    let b = 2;    let result = a + b; // result is 7 JavaScript Operators 2. Assignment Operators:    - `=` (Assignment): Assigns the value of the right operand to the left operand. ...

JavaScript Variables | var - let - const - Main ways to declare variables in JavaScript

Introduction to JavaScript Variables: In JavaScript, variables are used to store and manage data. A variable is a symbolic name (an identifier) for a value. Variables are declared using the var, let, or const keyword, and they can hold various types of data, such as numbers, strings, or objects. Here are the main ways to declare variables in JavaScript: 1. var: The var keyword was traditionally used for variable declaration in JavaScript. However, it has some scoping issues, and it is recommended to use let and const instead. Example:      javascript      var x = 10; JavaScript Variables 2. let: The let keyword is introduced in ECMAScript 6 (ES6) and is widely used for variable declaration. Variables declared with let are block-scoped. Example:      javascript      let message = "Hello, World!"; 3. const: The const keyword is also introduced in ES6 and is used to declare constants. Variables declared with const cannot be...