Unit 2: Data Types and Variables
Data types, operators, and variables in JavaScript.
Data types, operators, and variables in JavaScript.
Operators, Expressions, and Core Statements JavaScript combines values into expressions. Operators process these values. Statements form the operational logic that executes tasks. The language demands explicit termination and strict handling of whitespace. Statement Basics: Execution and Termination Statements are commands. They dictate execution. JavaScript is forgiving with whitespace. Spaces, tabs, and newlines separate tokens but do not affect execution logic. Termination defines the end of a statement. The semicolon (;) is the explicit terminator. JavaScript implements Automatic Semicolon Insertion (ASI). The engine attempts to infer missing semicolons during parsing. ASI is a structural hazard. It causes unpredictable execution when returning objects or anonymous functions. Robust code mandates explicit semicolons to prevent parser misinterpretations. ...
Data Types and Variables: Representation and Conversion JavaScript handles data through dynamic typing. The runtime engine determines type automatically. This removes static compilation overhead but introduces type coercion risks. Robust systems require explicit understanding of how JavaScript stores, converts, and evaluates data. Primitive Types and Number Literals JavaScript operates exclusively with double-precision 64-bit floating-point format (IEEE 754) for all numeric values. There are no native integers. This architectural decision creates specific data representation issues. Floating-point arithmetic cannot represent decimal fractions precisely. The evaluation of 0.1 + 0.2 results in 0.30000000000000004, not 0.3. Financial calculations and high-precision scientific operations must circumvent this hardware-level limitation using scaling logic or arbitrary-precision libraries. ...