Java Script Fundamentals - 1

JavaScript (JS) is a scripting or programming language that allows you to implement complex features on web pages. It is a lightweight programming language commonly used by web developers to add dynamic interactions to web pages, applications, servers, and even games.

1. Variables in JavaScript
In JavaScript, variables are used to store data values. They can be declared using the keywords var, let, or const.

2. Data Types in JavaScript (Primitive Types)

There are 7 primitive data types in JavaScript:

  1. Number – Represents both integer and floating-point numbers. For example: 42 or 3.14.

  2. String – Represents sequences of characters, like "hello", 'world'.

  3. Boolean – Represents true or false.

  4. Null – Represents a non-existent or invalid value. null is explicitly set.

  5. Undefined – A variable that has been declared but not assigned a value is undefined.

  6. Symbol – Represents a unique and immutable identifier (introduced in ES6).

  7. BigInt – Used for arbitrarily large integers (introduced in ES2020).

3. Number Types

  • Integer – Whole numbers like 5, 42, -23.

  • Float – Decimal numbers like 3.14, -2.5.

4. Operations in JavaScript

Basic arithmetic operations can be performed in JavaScript:

5. NaN in JavaScript

NaN stands for "Not-a-Number". It is a value that represents something that is not a valid number.

6. Operator Precedence

Operator precedence defines the order in which operations are performed.
order of precedence is
( ) parentheses** exponential* , / multiplication and division+ , - addition and subtraction
For example:

7. let, const, and var Keywords

  • var: Function-scoped, can be redeclared and reassigned.

  • let: Block-scoped, cannot be redeclared within the same block, but can be reassigned.

  • const: Block-scoped, cannot be redeclared or reassigned after initial assignment.

8. Assignment and Unary Operators

  • Assignment Operator: =

    you can see the different values of a using different equality operator

  • Unary Operators: Increment ++, Decrement --, plus +, minus

9. Identifier Rules in JavaScript

  • It must start with a letter, _, or $.

  • Subsequent characters can be letters, numbers, _, or $.

  • JavaScript is case-sensitive.

10. Boolean in JavaScript

Booleans represent two values: true or false.

11. Is JavaScript Dynamically Typed?

Yes, JavaScript is dynamically typed, meaning variables do not have types. The type of a variable is determined by the value assigned to it, and can change during execution.

12. String in JavaScript

A string is a sequence of characters enclosed in quotes (" " or ' ')

  • String Indices: Strings are zero-indexed means it’s index starts from 0

  • String Length: Use the .length property to get the length.

  • Concatenation: Use the + operator or template literals

13. Null and Undefined in JavaScript

  • null: Represents the intentional absence of any object value

  • undefined: Represents a variable that has been declared but not assigned a value.