Ai Coding Tools

How to Write Your First JavaScript Function with AI Assistance in 1 Hour

By BTW Team4 min read

Comparing tools? See the AI tools tested on the show.

In short

A step-by-step tutorial on leveraging AI tools to help you write and understand your first JavaScript function quickly.

If you're a beginner looking to dive into JavaScript, you might feel overwhelmed by the sheer amount of information out there. The good news is that AI tools have come a long way in 2026, making it easier than ever to get started. In this guide, I'll show you how to write your first JavaScript function using AI assistance—all in about an hour.

Prerequisites

Before we jump in, here’s what you need:

  • A computer with internet access
  • A code editor (like Visual Studio Code, which is free)
  • Basic understanding of programming concepts (variables, loops, etc.)
  • An AI coding assistant (we’ll cover some options below)

Step 1: Choose Your AI Tool

There are several AI coding tools that can assist you in writing JavaScript functions. Here’s a quick comparison of some popular options:

| Tool Name | Pricing | Best For | Limitations | Our Take | |-------------------|------------------------------|-------------------------------|--------------------------------------|--------------------------------| | GitHub Copilot | $10/mo (free trial available) | Beginners and experienced devs | Can suggest incorrect code | We use this for quick suggestions. | | Tabnine | Free tier + $12/mo pro | Auto-completion and suggestions | Limited to JavaScript and few other languages | We don’t use it as much; Copilot is better for us. | | Codeium | Free | Free coding assistance | Limited features compared to others | We haven't tried it yet. | | OpenAI Codex | $20/mo | Advanced coding tasks | More complex than necessary for beginners | Not ideal for first-time users. | | Replit AI | Free tier + $15/mo pro | Collaborative coding | Requires internet connection | We use it for team projects. | | Sourcery | Free | Code review and suggestions | Focuses more on Python | We don’t use this for JavaScript. |

What We Actually Use

For beginners, I recommend starting with GitHub Copilot. It’s user-friendly and provides excellent support for writing JavaScript functions.

Step 2: Set Up Your Environment

  1. Install Visual Studio Code: Download and install it from here.
  2. Install GitHub Copilot: If you choose this tool, follow the instructions here.
  3. Create a new JavaScript file: Open VS Code, create a new file, and save it as myFirstFunction.js.

Step 3: Write Your First Function

Now, let’s write a simple JavaScript function that adds two numbers together. Here’s how you can do it with the help of GitHub Copilot:

  1. Start typing the function: Begin by typing function add(a, b) { and then press Enter.
  2. Let Copilot suggest code: After the opening bracket, you can wait for Copilot to suggest the code. It often provides the complete function body.
  3. Accept the suggestion: If the suggestion looks good, you can accept it by pressing Tab.

Your code should look something like this:

function add(a, b) {
    return a + b;
}

Expected Output

When you call add(2, 3), it should return 5.

Step 4: Test Your Function

  1. Add test cases: Below your function, write some test cases like:
    console.log(add(2, 3)); // Output: 5
    console.log(add(-1, 1)); // Output: 0
    
  2. Run your code: You can run your code in the terminal by typing node myFirstFunction.js.

Troubleshooting

  • Error messages: If you see an error, double-check your syntax (missing brackets or semicolons are common issues).
  • Function not returning what you expect: Make sure you’re passing the correct parameters.

Step 5: What's Next?

Now that you’ve written your first function, you can explore more complex concepts like:

  • Function parameters and return types
  • Arrow functions
  • Higher-order functions

Consider building small projects to apply what you've learned, like a simple calculator or a to-do list app.

Conclusion

Getting started with JavaScript doesn’t have to be daunting, especially with AI tools like GitHub Copilot. By following these steps, you can write your first function in just about an hour.

Start here: Choose GitHub Copilot as your AI assistant, set up your environment, and dive into writing functions.

Watch real AI builds every week

Built This Week is a weekly podcast where Jordan Metzner and Sam Nadler build something real with AI every episode, test new AI tools and talk with founders who build with AI.

See the tools

Watch real AI builds every week

Built This Week is a weekly podcast where Jordan Metzner and Sam Nadler build something real with AI every episode, test new AI tools and talk with founders who build with AI.

See the tools
Ai Coding Tools

3 AI Coding Tools That Are Overrated (and Why You Should Avoid Them)

3 AI Coding Tools That Are Overrated (and Why You Should Avoid Them) In the everevolving landscape of AI coding tools, it's easy to get swept up in the hype. As indie hackers and s

Nov 30, 20263 min read
Ai Coding Tools

5 Ways AI Coding Tools Can Accelerate Your MVP Development in 2026

5 Ways AI Coding Tools Can Accelerate Your MVP Development in 2026 In 2026, the landscape for indie hackers and solo founders has evolved significantly, especially with the advent

Nov 26, 20264 min read
Ai Coding Tools

5 AI Coding Tools That Make Legacy Code Feel Brand New in 2026

5 AI Coding Tools That Make Legacy Code Feel Brand New in 2026 If you’re a developer stuck maintaining legacy code, you know the frustration. It’s like navigating a maze blindfolde

Nov 23, 20264 min read
Ai Coding Tools

10 AI Coding Tools That Will Save You Hours of Debugging in 2026

10 AI Coding Tools That Will Save You Hours of Debugging in 2026 Debugging can feel like a neverending cycle of frustration. Whether you're a solo founder or an indie hacker, spend

Nov 18, 20265 min read
Ai Coding Tools

10 Common Mistakes When Using AI Coding Tools for MVP Development

10 Common Mistakes When Using AI Coding Tools for MVP Development As a founder in 2026, you’re likely aware that AI coding tools can significantly speed up the MVP development proc

Nov 16, 20264 min read
Ai Coding Tools

5 AI Coding Myths Every Beginner Developer Should Ditch in 2026

5 AI Coding Myths Every Beginner Developer Should Ditch in 2026 As a beginner developer, you’ve probably come across a ton of buzz surrounding AI coding tools. But with all the hyp

Nov 12, 20263 min read