Skip to content

Instantly share code, notes, and snippets.

@connectplatform
Last active April 21, 2024 08:36
Show Gist options
  • Save connectplatform/57d5c68b6673783933f52d74227fe3ea to your computer and use it in GitHub Desktop.
Save connectplatform/57d5c68b6673783933f52d74227fe3ea to your computer and use it in GitHub Desktop.
javascript fundamentals

JavaScript Fundamentals

Data Structures: Your Data Organizers

Arrays: Think of an array like a special box with compartments. Each compartment holds one item, like a number, word, or even another box! You can find things by their number ("Give me item number 3!").

  • Example: Your grocery list is like an array: ["milk", "eggs", "bread"]

Objects: Think of an object like a backpack with different pockets. Each pocket has a name (like "color", "size") and holds something (like "red", "large"). You grab things by their pocket's name ("Give me what's in the 'color' pocket!").

  • Example: A description of your dog could be an object: { name: "Buddy", breed: "Golden Retriever", age: 3 }

Dictionaries (Not always in JavaScript, but good to know!) Like a super-organized address book. You have a key (like a person's name) and it lets you look up their number.

Control Flow: The Decision Maker

Imagine you're baking cookies. You have a recipe with steps, but what if you run out of flour? That's where control flow comes in! It's like the boss of your code, deciding which steps to follow based on certain conditions, just like you might have to substitute ingredients in your recipe.

Here are the different ways control flow can make decisions in your code:

  • If/Else Statements: Like asking a question with "if". If it's true, do one thing. If it's false ("else"), do something different.

    • Example:
      if (backpackColor == "blue") {
          wearJeans(); // It's a blue backpack, so jeans look good
      } else {
          wearBlackPants(); // Any other color, black pants are safe
      }
  • Loops: For repeating things.

    • For Loops: Perfect when you know how many times to repeat. ("Clean your room 5 times!")
    • While Loops: Keep going until something is true ("Keep playing until it gets dark out!")
  • Functions: Your Reusable Helpers

    • Like little machines you build! They have a name (like "makeBreakfast") and instructions inside. You "call" the function, give it ingredients (like "eggs", "toast"), and it delivers a result (a tasty breakfast!).
    • Example
      function makeSandwich(breadType, filling) {
          // Steps to put the sandwich together 
          return "Here's your sandwich!"; 
      }
      
      // Now you can use it:
      let myLunch = makeSandwich("wheat", "peanut butter");

How this helps your TurboWarp Extension:

  • Data Structures: Store your extension's settings, information about the game it's in, etc.
  • Control Flow: Make your extension react to things happening in the game, or let the user make choices.
  • Functions: Keeps your code neat, stops you from repeating the same instructions all the time!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment