Variables and Objects

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Accessing a variable in its TDZ will result in a ______ error.

Reference

Which declaration is affected by the TDZ?

  • var
  • function
  • let (correct)
  • const

Objects are collections of key–value pairs used to represent structured data.

True (A)

In an object literal, keys are paired with values using a ______.

<p>colon</p> Signup and view all the answers

Which statement about objects is false?

<p>They are always immutable by default. (D)</p> Signup and view all the answers

In many languages, assigning an object to a variable stores a reference to that object rather than a copy of it.

<p>True (A)</p> Signup and view all the answers

When two variables reference the same object, changes via one variable will be visible through the ______ variable.

<p>other</p> Signup and view all the answers

Mutation means modifying the state or data within an object.

<p>True (A)</p> Signup and view all the answers

Which of the following scenarios demonstrates the concept of mutability?

<p>Modifying an object's properties without changing its identity. (B)</p> Signup and view all the answers

A variable declaration always reserves memory space for the variable's value.

<p>False (B)</p> Signup and view all the answers

What is the primary difference between declaration and initialization of a variable?

<p>Declaration introduces the variable's name and type, whereas initialization assigns it an initial value.</p> Signup and view all the answers

In many programming languages, failure to initialize a variable before using it results in a(n) ______.

<p>error</p> Signup and view all the answers

Which action demonstrates a reassignment operation?

<p>Modifying a variable's value after it was initially set. (D)</p> Signup and view all the answers

Reassigning a variable changes its memory address.

<p>False (B)</p> Signup and view all the answers

The primary purpose of a variable is to store ______ for later use in a program.

<p>data</p> Signup and view all the answers

Which of the following is NOT a characteristic of a variable?

<p>A variable's name must start with a number. (C)</p> Signup and view all the answers

Variable assignment is a structural element that directs the order of execution.

<p>False (B)</p> Signup and view all the answers

Which of the following is NOT a typical characteristic of synchronous code execution?

<p>Multiple operations run concurrently. (B)</p> Signup and view all the answers

In the context of asynchronous programming, _______ are commonly used to manage operations that occur out-of-sequence without blocking execution.

<p>callbacks</p> Signup and view all the answers

Asynchronous operations block other code from running while waiting for long-running tasks to complete.

<p>False (B)</p> Signup and view all the answers

Which programming paradigm is characterized by hiding complex details and exposing only essential features?

<p>Abstraction (B)</p> Signup and view all the answers

Abstraction helps in reducing complexity by focusing on ______ details, hiding unnecessary information.

<p>essential</p> Signup and view all the answers

Match the characteristic with the correct type of operation:

<p>Synchronous = Code execution is blocked until operation is complete Asynchronous = Code execution continues without waiting for the operation to finish Abstraction = Hides complex details and exposes simplified interfaces.</p> Signup and view all the answers

Describe a scenario where using asynchronous programming would be more beneficial than synchronous programming.

<p>When performing tasks such as network requests or file I/O that might take a significant amount of time, asynchronous programming allows the program to remain responsive by continuing to execute other tasks while waiting for the long-running operation to complete.</p> Signup and view all the answers

Abstraction helps in managing complexity by:

<p>Simplifying interactions with complex systems through a simpler interface. (C)</p> Signup and view all the answers

An algorithm is best described as a suggestion for solving a problem.

<p>False (B)</p> Signup and view all the answers

The efficiency of an algorithm can be measured in terms of time complexity, and also how much ______ it consumes.

<p>space</p> Signup and view all the answers

Which of the following is the MOST suitable to be called algorithm?

<p>A function that searches an element in a list (D)</p> Signup and view all the answers

An API is a hardware component that facilitates communication between software applications.

<p>False (B)</p> Signup and view all the answers

APIs enable different software systems to easily ______ and share data with each other.

<p>communicate</p> Signup and view all the answers

Which of the following is NOT a typical function of an API?

<p>Directly managing and controlling the operating system's kernel. (C)</p> Signup and view all the answers

A software bug is best described as:

<p>An error or flaw in a program that causes unintended behavior. (A)</p> Signup and view all the answers

Which action is least aligned with the goals of refactoring?

<p>Adding new functionalities (A)</p> Signup and view all the answers

Comprehensive documentation is most critical during the initial development phase and loses relevance as the project matures.

<p>False (B)</p> Signup and view all the answers

When onboarding a new developer to a project, good documentation helps them quickly __________ the codebase.

<p>understand</p> Signup and view all the answers

Which aspect of software development most directly benefits from well-crafted documentation?

<p>Team collaboration and knowledge sharing (C)</p> Signup and view all the answers

Briefly explain how refactoring and documentation complement each other in software development.

<p>Refactoring improves code structure, while documentation explains that structure and functionality. Together, they enhance maintainability and understanding.</p> Signup and view all the answers

Which of the following demonstrates the primary benefit of encapsulation?

<p>It reduces complexity and increases reusability. (D)</p> Signup and view all the answers

Exception handling is primarily used to prevent all errors from occurring during program execution.

<p>False (B)</p> Signup and view all the answers

In exception handling, the ______ block typically contains the code that might potentially throw an exception.

<p>try</p> Signup and view all the answers

Which characteristic is least likely found within a framework?

<p>A completely unique architecture for each project (A)</p> Signup and view all the answers

By providing common functionalities, a framework can significantly decrease development time and effort by reducing the need to write code from ______.

<p>scratch</p> Signup and view all the answers

Garbage collection requires manual intervention by the programmer to identify and deallocate unused memory.

<p>False (B)</p> Signup and view all the answers

How does garbage collection contribute to the reliability of a software application?

<p>By automatically freeing up memory occupied by unreachable objects (C)</p> Signup and view all the answers

Inheritance promotes code reusability by eliminating the need to define similar properties and methods in multiple classes.

<p>True (A)</p> Signup and view all the answers

Flashcards

Mutable Objects

Objects that can be modified after creation.

Mutability Example

A list that allows adding or removing elements.

Declaration

Introducing a variable name into a program’s scope.

Declaration (in terms of value)

Creating an identifier without an initial value.

Signup and view all the flashcards

Declaration Description

Introducing a new variable name in code.

Signup and view all the flashcards

Initialization

Assigning a variable its first value.

Signup and view all the flashcards

Reassignment

Giving an already declared variable a new value.

Signup and view all the flashcards

Variables

Storage locations with a name that holds data values.

Signup and view all the flashcards

Temporal Dead Zone (TDZ)

The period when a variable exists but is inaccessible before its declaration.

Signup and view all the flashcards

TDZ Error Type

An error that occurs when trying to access a variable in its TDZ.

Signup and view all the flashcards

Declarations with TDZ

Variables declared with 'let' and 'const' are affected.

Signup and view all the flashcards

Objects

Collections of key-value pairs for representing structured data.

Signup and view all the flashcards

Key-value pair separator

A colon.

Signup and view all the flashcards

Mutation (Objects)

Modifying an object's state (properties or content).

Signup and view all the flashcards

Object References

Storing an object's memory address, not a full copy, in a variable.

Signup and view all the flashcards

In-place change to an object

Altering the properties or content of an existing object directly.

Signup and view all the flashcards

Variable Assignment

An action that assigns a value to a variable, not a control structure.

Signup and view all the flashcards

Synchronous

Operations execute one after another, blocking subsequent code until each is complete.

Signup and view all the flashcards

Synchronous Model

Tasks are executed sequentially, each waiting for the previous one to finish.

Signup and view all the flashcards

Synchronous Characteristic

Each operation must complete before the next begins.

Signup and view all the flashcards

Asynchronous

Operations allow other code to run while waiting for long-running tasks to complete.

Signup and view all the flashcards

Asynchronous code handling

Callbacks, promises, or async/await are common approaches.

Signup and view all the flashcards

Asynchronous Programming

Code that executes concurrently, improving responsiveness.

Signup and view all the flashcards

Abstraction

Hiding complexity and exposing only necessary parts.

Signup and view all the flashcards

Algorithm

A step-by-step procedure for solving a problem.

Signup and view all the flashcards

Algorithm Efficiency

A measure of the resources (time and space) an algorithm uses.

Signup and view all the flashcards

Sorting Algorithm

A function that sorts elements in an array.

Signup and view all the flashcards

API (Application Programming Interface)

Defines protocols for building and interacting with software applications.

Signup and view all the flashcards

API Communication

Allows different software systems to communicate with each other.

Signup and view all the flashcards

Bug

An error or flaw in a program that causes unexpected behavior.

Signup and view all the flashcards

Debugging

The process of finding and fixing bugs.

Signup and view all the flashcards

Code Refactoring

Simplifying code without changing its behavior to improve understanding and maintainability.

Signup and view all the flashcards

Code Documentation

Detailed information explaining how a program works and how to use it.

Signup and view all the flashcards

Why document?

To grasp the functionality and structure of the codebase.

Signup and view all the flashcards

Purpose of Documentation

Serves as a reference explaining code functionality and usage for developers and users.

Signup and view all the flashcards

Maintaining Code

Maintaining code, especially when new developers join the project.

Signup and view all the flashcards

Encapsulation

Bundling data and methods that operate on that data, hiding internal details.

Signup and view all the flashcards

Exception Handling

A mechanism to gracefully manage errors that occur during runtime.

Signup and view all the flashcards

Catch Block

A block of code used to catch exceptions.

Signup and view all the flashcards

Framework

A pre-built structure providing tools to build applications faster.

Signup and view all the flashcards

Garbage Collection

Automatically reclaiming memory from objects no longer in use.

Signup and view all the flashcards

Purpose of Garbage Collection

Frees up memory by removing unreachable objects.

Signup and view all the flashcards

Inheritance

Acquiring properties and methods from another class.

Signup and view all the flashcards

Inheritance

Allows one class to acquire another class properties.

Signup and view all the flashcards

Study Notes

Literals

  • A literal is a hardcoded value that is written directly into the source code
  • Literals are fixed values like numbers or strings that appear directly in the code and do not require computation
  • An object literal uses curly braces to specify properties immediately rather than constructing the object via a function
  • "Hello, World!" is an example of a literal

Constructor

  • A constructor is a special function that is used to initialize new objects
  • Constructors set up a new object's properties and initial state when the object is created
  • The keyword this refers to the current object being created or manipulated within a constructor

Immutability

  • An immutable value cannot be altered once it is created
  • Immutability means that the value stays constant after it's set
  • In an immutable data structure, any operation that appears to change it will instead return a new version of the structure
  • Strings in many languages are typically immutable

Mutability

  • A mutable object can be modified after its creation
  • Mutability allows an object's state or properties to change over time
  • When an object is mutable, its state can be changed without creating a new instance
  • Mutable objects permit in-place modifications
  • Lists (in many languages) allow changes such as appending or removing elements, which best illustrates mutability

Declaration

  • Declaration is the process of introducing a variable name into a program's scope
  • Declarations create a variable identifier without necessarily assigning a value
  • Declaring a variable means creating an identifier without necessarily assigning it an initial value
  • A declaration reserves a name in the code, while initialization assigns a value
  • Declaration brings a variable into existence within a given scope

Initialization

  • Initialization is the process of assigning a variable with its first value
  • Initialization gives the declared variable an initial value
  • A variable can be declared first and initialized later, as they are conceptually different steps
  • int x = 10; shows both declaration and initialization

Reassignment

  • Reassignment is the act of giving an already declared variable a new value
  • Reassignment changes the value stored in a variable after it has been initialized
  • After a variable is initialized, changing its value is known as reassignment
  • This term specifically refers to updating the value of an existing variable

Variables

  • Variables are storage locations which are identified by a name that holds data values
  • Variables act as containers for storing and referencing data in memory
  • Variables declared with let or const in JavaScript are block-scoped
  • In languages like JavaScript, let and const limit a variable's accessibility to the block where it's declared
  • A common characteristic of variables is that they can be reassigned if mutable

Hoisting

  • Hoisting refers to the process where variable and function declarations are moved to the top of their scope
  • In JavaScript, declarations are hoisted, but initializations remain in place
  • Only the declaration of a variable declared with var is hoisted, not its assigned value
  • Hoisting rearranges the code during compilation so that declarations are known before execution

Scope

  • Scope determines where variables and functions are accessible in a program
  • Scope limits the visibility of variables and functions to certain parts of the code
  • Variables declared inside a function are in the local scope of that function
  • Local scope confines variables to the function in which they are declared
  • Block scope means that variables only exist within the block, such as within curly braces

TDZ (Temporal Dead Zone)

  • The Temporal Dead Zone (TDZ) refers to the time between entering a scope and when a let/const variable is declared
  • The TDZ is a period where variables exist in theory but cannot be accessed until declared
  • Accessing a variable in its TDZ will result in a ReferenceError
  • Variables declared with let and const have a TDZ; var does not

Objects

  • Objects are collections of key-value pairs used to represent structured data
  • Objects bundle related data together in properties and methods
  • In an object literal, keys are paired with values using a colon
  • The colon separates each key from its corresponding value in literal syntax
  • It is false that Objects are always immutable by default

References

  • In many languages, assigning an object to a variable stores a reference to that object rather than a copy of it
  • A variable holds the memory address of the object, so changes through one reference are seen by all
  • When two variables reference the same object, changes via one variable will be visible through the other variable
  • Since both variables point to the same object, modifications affect the single shared instance
  • A reference simply points to where the object resides in memory rather than duplicating it

Mutation

  • Mutation means modifying the state or data within an object
  • Mutation involves changing the properties or content of an existing object
  • An operation that changes an object in place is called mutation
  • Mutation directly alters the object's state instead of creating a new object
  • Changing a property value within an existing object is an example of mutation

Type Coercion

  • Type coercion is the implicit conversion of values from one data type to another
  • Languages like JavaScript automatically convert types when operators expect a different type
  • When a language performs type coercion, it automatically converts one data type into another without explicit instructions
  • Implicit coercion happens automatically as part of language rules during evaluation
  • "5" + 2 resulting in "52" is an example of type coercion in JavaScript, where the number 2 is converted to a string, leading to concatenation

Type Conversion

  • Type conversion can be either explicit (by the programmer) or implicit (automatically by the language)
  • Converting a value from one type to another using a function like Number() is an example of explicit conversion
  • Explicit conversion requires the programmer to manually convert a value from one type to another
  • Explicit conversion functions like parseInt() or String() are used for type conversion in many languages

Explicit Conversion

  • Explicit conversion requires the programmer to manually convert a value from one type to another
  • The programmer directly calls a conversion function, making the intent clear
  • Using a function like Number() or parseInt() to convert a string to a number is an example of explicit conversion
  • Explicit conversion avoids ambiguity by clearly stating the conversion

Implicit Coercion

  • Implicit coercion happens automatically without the programmer's explicit instruction
  • The language converts types on its own when needed by context
  • Implicit coercion may lead to unexpected results if the language's rules are not well understood
  • Automatic conversions can sometimes produce results that differ from programmer expectations
  • One risk associated with implicit coercion is that it can introduce subtle bugs due to unexpected type conversions

Functions

  • Functions are reusable blocks of code that can accept inputs and return outputs
  • Functions encapsulate code logic so it can be called repeatedly with different inputs
  • Functions are considered first-class citizens because they can be passed as arguments
  • First-class functions are treated as values that can be assigned, passed, and returned

Expressions

  • An expression is any valid unit of code that resolves to a value
  • Expressions are evaluated to produce data, making them fundamental units in programming
  • The statement 2 + 3 is an example of an arithmetic expression
  • Expressions compute a value and are recognized

Arguments

  • Arguments are the actual values that are passed to a function during a call
  • When a function is called, the provided values are known as arguments
  • In the function call sum(3, 4), the numbers 3 and 4 are called arguments
  • Arguments are the specific values supplied to the function parameters
  • Arguments are the real data passed to functions during a call

Statements

  • A statement is an instruction that performs an action but may not necessarily produce a value
  • Statements control program behavior (like loops or conditionals) without needing to resolve to a value
  • In many languages, a statement ends with a delimiter, such as a semicolon
  • A delimiter signifies the end of a statement

HOFs (Higher-Order Functions)

  • Higher-order functions can take other functions as arguments or return them
  • Higher-order functions operate on functions, allowing for more abstract and modular code
  • Functions like map, filter, and reduce are common examples of higher-order functions
  • They either accept functions as parameters or return functions, qualifying as higher-order
  • They enable function composition and abstraction, which allow for composing complex operations

Iterations

  • Iteration is the process of repeating a block of code until a condition is met
  • Iteration enables repetitive tasks by executing code multiple times
  • Using a for loop or a while loop is a common way to perform iteration in many programming languages
  • Iteration focuses on repeatedly executing a set of instructions

Loops

  • Loops are control structures that repeatedly execute code based on a condition
  • Loops provide a means to execute code repeatedly while a condition remains true
  • A do-while loop executes its block at least once before checking the condition
  • In a do-while loop, the code block is executed first and then the condition is checked
  • A while loop checks the condition before each iteration

Iterable

  • An iterable is any object that can be looped over, such as arrays or strings
  • Iterables implement protocols like Symbol.iterator in JavaScript that allow their elements to be accessed sequentially
  • In JavaScript, an object is iterable if it implements the Symbol.iterator method
  • Plain objects are not iterable by default
  • They do not implement an iterator by default, so they cannot be looped over using iteration constructs like the for-of loop

Control Flow

  • Control flow determines the order in which code statements are executed
  • Control flow structures (such as conditionals and loops) guide the path of execution in a program
  • Conditional statements and loops are constructs that manage control flow in a program
  • These constructs explicitly dictate how the program's execution path is directed
  • Variable assignment is an action and not a control flow structure

Synchronous

  • Synchronous operations are executed one after another, blocking subsequent code until completion
  • Synchronous code waits for each operation to finish before moving on
  • Each operation must complete before the next begins in synchronous code
  • Synchronous code is inherently sequential, ensuring each step is completed in order

Asynchronous

  • Asynchronous operations allow other code to run while waiting for long-running tasks to complete
  • Asynchronous programming lets the system continue executing other code instead of waiting for operations like I/O to finish
  • The use of callbacks, promises, or async/await are common approaches to handling asynchronous code
  • These constructs manage operations that occur out-of-sequence without blocking execution
  • Asynchronous programming allows multiple operations to proceed without waiting for each to finish sequentially

Abstraction

  • Abstraction involves hiding the complex reality while exposing only the necessary parts of an object or system
  • Abstraction reduces complexity by allowing interaction with simplified interfaces
  • Abstraction helps reduce complexity by focusing on essential details
  • It hides unneeded details so the focus can be on what's important
  • Abstraction simplifies interaction with complex systems by exposing a simpler interface

Algorithm

  • An algorithm is a step-by-step procedure for solving a problem
  • Algorithms are the recipes or instructions that solve specific computational problems
  • The efficiency of an algorithm is often measured in terms of time and space complexity
  • Both time and space complexity are key metrics used to access algorithm performance
  • Sorting is a common algorithmic problem with specific step-by-step methods

API (Application Programming Interface)

  • An API defines a set of protocols for building and interacting with software applications
  • APIs provide standardized methods and rules for software components to interact
  • APIs allow different software systems to communicate with each other
  • The main role of an API is to facilitate communication between systems
  • APIs abstract functionality; they do not directly alter hardware

Bug

  • A bug is an error or flaw in a program that causes unexpected behavior
  • Bugs are mistakes in code that lead to incorrect or unexpected program behavior
  • The process of finding and fixing bugs is known as debugging
  • Debugging is the systematic process of locating and correcting errors
  • Bugs can lead to security vulnerabilities

Class

  • A class is a blueprint for creating objects, defining properties and methods
  • Classes provide a template for objects, specifying common properties and behaviors
  • An object is an instance of a class in object-oriented programming
  • Classes serve as blueprints that produce objects with defined attributes and methods

Compilation

  • Compilation is the process of translating source code into machine code
  • Compilers convert high-level language code into a form that can be executed by the machine
  • A compiler is the program that performs the compilation of source code
  • A compiler reads source code and generates the corresponding machine-level instructions
  • Compilation prepares code for execution by translating it before the program runs

Compiler

  • A compiler translates code from a high-level language to a low-level language such as machine code
  • This translation is essential for the computer to understand and execute the code
  • The main role of a compiler is to translate code for execution by the computer's processor
  • Translation is at the core of a compiler's function
  • Compilers perform syntax checking, optimization of code and generate executable code

Data Structures

  • Data structures are ways to organize and store data for efficient access and modification
  • They determine how data is stored and accessed, impacting performance
  • Common data structures include arrays, lists, trees, and graphs
  • Graphs is another common data structure type used to model relationships
  • A binary tree is structured which organizes the way to organize data hierarchically

Debugging

  • Debugging is identifying errors in a program
  • Debugging involves systematically finding and correcting issues in code
  • A debugger helps developers step through code to locate bugs
  • A debugger is a tool that is used to observe code execution to identify problems
  • An integrated Development Environment (IDE) tool is commonly used for debugging

Dependency Injection

  • Dependency injection is a design pattern where an object's dependencies are provided externally, rather than being created within the object
  • This pattern decouples object creation from usage, making code more modular and testable
  • Dependency injection promotes modularity by decoupling the creation of dependencies from their usage
  • By injecting dependencies, it's possible to swap them out for maintenance

Encapsulation

  • Encapsulation is the bundling of data and methods that operate on the data into a single unit
  • Encapsulation hides internal details and only exposes the necessary components
  • It helps protect an object's internal state from unauthorized access
  • It prevents code from altering internal properties directly
  • Encapsulation ensures reusable objects that manage their own code

Exception Handling

  • Exception handling is a mechanism designed to mange runtime errors gracefully
  • It allows programs to recover or fail gracefully when errors occur
  • A block of code that catches exceptions is typically labeled catch in many languages
  • The "try...catch" structure is the standard structure for handling exceptions

Framework

  • A framework provides a prebuilt structure as well as a set of tools built for applications
  • Framework offers reusable components and conventions to speed up development
  • A framework will drastically reduce development time by providing common functionalities and patterns
  • When a developer reuses prebuilt functionalities, the developer does not need to write common code from scratch
  • Angular is a full-fledged framework that provides structure and tools for building web applications

Garbage Collection

  • Garbage collection is an automated process of clearing memory from objects no longer in use
  • Languages such as Java uses garbage collection to manage memory automatically
  • Languages such as Java and c# use garbage collection to manage memory automatically
  • The main purpose of garbage collection is to free up memory by removing unreachable objects
  • Garbage collection will keep the system efficient because it reclaims unused memory and ensures memory is reclaimed

Inheritance

  • Inheritance allows one class to acquire properties and methods of another class
  • Inheritance promotes code reuse by letting a class inherit features from a parent class
  • In object-oriented programming, a subclass inherits from a superclass
  • The parent class derives the superclass from where the child class derives
  • It can allow for code reuse and hierarchical organization

IDE (Integrated Development Environment)

  • An IDE typically includes a code editor, a debugger, and automatic building tools
  • IDEs consolidate multiple development tools into one application for efficiently
  • An IDE can help streamline the development process by providing intergrated tooosl
  • IDEs simplify coding by integrating build systems, debuggers, and editors
  • Visual Studio Code is a popular IDE with numerous integrated tools

Interface

  • An interface defines a contract of methods that a class must implement without specifying how they are implement
  • Interfaces specify what methods exists and should be implemented in the details of the class
  • Interfaces specify method signatures that a class should implement
  • The interfaces only outlines the amount of parameters without the method and their name
  • It allows different classes to be used interchangeably if they implement the same interface

Library

  • A library is a collection of prewritten code taht developers can call upon to preform common tasks
  • Libraries provide reusable code modules saving time by avoiding the rewriting of common functionalities
  • Using a library prevents the need to reinvent code from scratch
  • Libraries offer ready-to-use solutions reducing complexity
  • Libraries are not integrated into every programming language by default

OOP (Object Oriented Programming)

  • An OOP is a programming paradigm that organizes code around objects and data rather than actions and logic
  • OOPs are based on objects that encapsulate data and behavior, structuring structures around them
  • Encapsulation,Inheritence, Polymorphism, and Abstraction are the four pillars of OOP

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser