Skip to content

Instantly share code, notes, and snippets.

@humayunahmed8
Created February 12, 2024 14:13
Show Gist options
  • Save humayunahmed8/31f858713933bbaec25579f81cd37e0a to your computer and use it in GitHub Desktop.
Save humayunahmed8/31f858713933bbaec25579f81cd37e0a to your computer and use it in GitHub Desktop.
Javascript Statement
// Javascript Statement
/*
1. A statement is a complete line of code that performs
some action. It may or may not result in a value.
2. Statements typically perform tasks such as variable assignment,
control flow (if statements, loops), function declarations, etc.
*/
// JavaScript statements are composed of:
/*
1. Values
2. Operators
3. Expressions
4. Keywords and
5. Comments
*/
// Example 1 :
/* This statement tells the browser to write "Hello World"
inside an HTML element with id="demo"
*/
// document.getElementById("demo").innerHTML = "Hello World";
// Example 2 :
let a, b, c
a = 5;
b = 5;
c = a + b;
console.log(c);
// Javascript Values
/*
In JavaScript, values are the basic building blocks of any program.
They represent data that can be manipulated and operated
on by the program. JavaScript has several types of values
*/
// Primitive Values:
let num = 42; // Number
let str = 'Hello'; // String
let bool = true; // Boolean
let undef; // Undefined
let nul = null; // Null
let nan = 0 / 0; // NaN
let inf = Infinity; // Infinity
let negInf = -Infinity; // -Infinity
// Complex Values:
let obj = { name: 'John', age: 30 }; // Object
let arr = [1, 2, 3, 4]; // Array
let func = function() { console.log('Hello, world!'); }; // Function
// Javascript Expression:
// An expression is a combination of values, variables, and operators, which computes to a value.
/*
1. An expression is any valid unit of code that resolves to a value.
2. It can consist of variables, operators, literals, and function calls.
3. Expressions can be simple or complex.
*/
// Example
x = 5;
y = 7;
z = (x != y) ? "YES" : "NO"; // NO
console.log(z);
var p = "John Doe";
var p = 0;
console.log(p)
/*
1. **Arithmetic Operators**: Used to perform mathematical calculations.
- Addition: `+`
- Subtraction: `-`
- Multiplication: `*`
- Division: `/`
- Modulus (remainder): `%`
- Exponentiation: `**` (ES7)
2. **Assignment Operators**: Used to assign values to variables.
- Assignment: `=`
- Addition assignment: `+=`
- Subtraction assignment: `-=`
- Multiplication assignment: `*=`
- Division assignment: `/=`
- Modulus assignment: `%=`
3. **Comparison Operators**: Used to compare values.
- Equal to: `==` or `===`
- Not equal to: `!=` or `!==`
- Greater than: `>`
- Less than: `<`
- Greater than or equal to: `>=`
- Less than or equal to: `<=`
4. **Logical Operators**: Used to perform logical operations.
- Logical AND: `&&`
- Logical OR: `||`
- Logical NOT: `!`
5. **Bitwise Operators**: Used to perform bitwise operations.
- Bitwise AND: `&`
- Bitwise OR: `|`
- Bitwise XOR: `^`
- Bitwise NOT: `~`
- Left shift: `<<`
- Sign-propagating right shift: `>>`
- Zero-fill right shift: `>>>`
6. **Unary Operators**: Operate on a single operand.
- Increment: `++`
- Decrement: `--`
- Unary plus: `+`
- Unary minus: `-`
- Logical NOT: `!`
- Typeof: `typeof`
- Void: `void`
- Delete: `delete`
7. **Ternary Operator**: A conditional operator.
- Syntax: `condition ? expr1 : expr2`
8. **String Concatenation Operator**: Used to concatenate strings.
- Concatenation: `+`
9. **Type Operators**: Used to determine the type of a variable.
- Instanceof: `instanceof`
- Typeof: `typeof`
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment