JavaScript Fundamentals: Quick Reference Cheat Sheet

Classified in Computers

Written at on English with a size of 2.61 KB.

JavaScript Fundamentals Cheat Sheet

1. Variables

  • let: Used to declare variables that are block-scoped. This means they only exist within the block they are defined in (e.g., inside a loop or an if statement).
  • const: Used for constants, which are also block-scoped. Once assigned a value, they cannot be reassigned.
  • var: Declares variables that are function-scoped. This can lead to issues with variable hoisting and is generally less preferred in modern JavaScript.

2. Functions

  • Functions are reusable blocks of code designed to perform a specific task. They can take parameters (inputs) and can return values.
  • Functions can be defined in different ways, including traditional function declarations and arrow functions, which provide a more concise syntax.

3. Control Structures

  • If Statements: Allow you to execute code based on whether a condition is true or false. You can use else if and else to handle multiple conditions.

4. Loops

  • Loops are used to execute a block of code repeatedly based on a condition.
    • For Loop: Commonly used when you know the number of iterations in advance.
    • For...of Loop: Used to iterate over iterable objects like arrays, making it easy to access each element.
    • While Loop: Continues executing as long as a specified condition remains true.

5. Arrays

  • Arrays are ordered collections of values. They can hold multiple items and provide various methods for manipulating those items (like adding or removing elements).
  • Arrays are dynamic, meaning their size can change as you add or remove items.

6. Object Literals

  • Objects are collections of key-value pairs, where each key is a string (property name) and the value can be any data type. Objects allow you to group related data and functions together.

7. Constructors

  • Constructors are special functions used to create objects. When called with the new keyword, they create an instance of an object with properties and methods defined in the constructor.
  • They enable the creation of multiple similar objects with the same structure.

8. Methods

  • Methods are functions that are associated with objects. They allow objects to perform actions using their own data and can be called using the object they belong to.

Entradas relacionadas: