Introduction to js and ts Flashcards
What is JavaScript?
A lightweight, interpreted programming language with object-oriented capabilities, commonly used in web pages and capable of running on browsers, servers, and devices with a JavaScript engine.
Key Features of JavaScript
Single-threaded: Executes one task at a time.
Non-blocking & Asynchronous: Continues execution without waiting for API calls or I/O events.
Concurrent: Overlaps task execution without simultaneous processing.
JavaScript Code Structure
Single Statements: End with a semicolon ;.
Variables: Declared using var, let, or const.
-var: Global variables.
-let: Block-scoped, reassignable.
-const: Block-scoped, immutable.
Variable Naming Rules
Only use letters, digits, $, and _.
Cannot start with a digit.
Case-sensitive.
Cannot use reserved words.
Data Types in JavaScript
Primitive Data Types:
String: Textual data.
Number & BigInt: Numbers.
Boolean: Logical values (true/false).
Null: Absence of value.
Undefined: Unassigned variable.
Non-Primitive Data Types:
Object: Keyed collections.
Array: Stores multiple elements.
Mutable vs. Immutable Types
Mutable: Non-primitive types; changes affect all references.
Immutable: Primitive types; changes create a new value.
Memory Management
Stack: Stores value types (e.g., primitives).
Heap: Stores reference types (e.g., objects).
String Methods
padStart, padEnd, charAt, charCodeAt, split, indexOf, lastIndexOf, search, slice, substring, substr, replace, toUpperCase, toLowerCase, concat, trim
Template Literals
Use backticks (`).
Features: Multiline strings, string interpolation, and HTML escaping.
Numbers & Type Conversion
Number Methods:
toString, toExponential, toFixed, toPrecision, valueOf.
Type Conversion:
String to Number: Number(“3.14”) → 3.14
Number to String: String(123) → “123”
Boolean Conversion:
Boolean(1) → true
Boolean(“”) → false
Date Methods
Set Methods: setDate, setFullYear, setHours, etc.
Get Methods: getFullYear, getMonth, getDate, Date.now, etc
Operators in JavaScript
Basic Operators: +, -, *, /, %, **.
Increment & Decrement:
Prefix (++x): Returns updated value.
Postfix (x++): Returns original value.
What is TypeScript?
A superset of JavaScript with static typing, helping catch errors early and improving code maintainability.
Why Use TypeScript?
Improved type safety.
Better readability.
Increased productivity.
Getting Started with TypeScript
Install via npm or yarn.
Create .ts files.
Write TypeScript code.
Compile to JavaScript using the TypeScript compiler.