Class-3
Class 3 – Introduction to JavaScript
Class Slides: class 3.1
This lecture focuses on arithmetic operations, increment/decrement operators, string concatenation, and user input handling in JavaScript. These fundamental concepts help in performing calculations, manipulating strings, and handling user inputs efficiently.
Key Topics Covered:
1. Arithmetic Operators:
- Enable mathematical calculations such as addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
- Essential for financial calculations, game mechanics, animations, and data processing.
- Operator precedence follows the BODMAS rule, meaning multiplication and division execute before addition and subtraction.
- Use of parentheses to alter execution order for correct calculations.
2. Increment and Decrement Operators:
- Increment (++) increases a variable’s value by 1.
- Decrement (–) decreases a variable’s value by 1.
- Can be used in two forms:
- Prefix (++x / –x): The value changes before being used in an expression.
- Postfix (x++ / x–): The value changes after being used in an expression.
- Frequently used in loops and counters.
3. String Concatenation:
- The
+operator joins multiple strings together. - Numbers and strings can be concatenated to form meaningful messages (e.g.,
"Score: " + 10). - Variables can be included in string concatenation to generate dynamic content.
4. User Input Handling:
- Prompt Box (
prompt()): Allows users to enter data as a string. - Parsing Strings to Numbers:
parseInt()converts a string into an integer.parseFloat()converts a string into a decimal number.
- Confirm Box (
confirm()): Displays a dialog box with “OK” and “Cancel” options, often used for user confirmation.
This session introduces the core mathematical and string operations in JavaScript, providing a foundation for interactive applications. Understanding these concepts is essential for developing dynamic web applications, form validation, and interactive user experiences.
