Coding Ireland STEM Report 2024 Have Your Say
Microbit JavaScript Coding Basics
Advanced
60 mins
270 points
What you need:
  • Computer/laptop

Introduction to JavaScript

What is JavaScript? In this lesson we learn about JavaScript and how is it different from programming with Scratch or other block programming languages. We will also start creating our first piece of code in JavaScript.

1 - What is JavaScript?

Just like we have many different languages in the world like English, French, Spanish, Japanese and so on, there are many different programming languages in the world and JavaScript is one of those.

In fact it's actually the most popular programming language and is used by nearly every website because it is very useful for making websites interactive.

So far you have learned how to create code used blocks like these:

basic.showString("Hello!")

JavaScript is a textual programming language which means that we type out the code rather than using blocks. Here is the same code as above but in the JavaScript language:

basic.showString("Hello!")

2 - Sequence

When we run our blocks code, the computer runs the first block in the sequence, then the next, then the next and so on.

basic.showNumber(1)
basic.showNumber(2)
basic.showNumber(3)

JavaScript does the same thing, it runs the first line of code, then the next line, then the next line and so on.

basic.showNumber(1)
basic.showNumber(2)
basic.showNumber(3)

3 - Try some JavaScript!

Let's dive in and try write your first piece of JavaScript code. The Makecode Microbit project editor also let's you write your code in JavaScript so we will use that.

Go to the https://makecode.microbit.org website and create a new project.

4 - Create code using blocks

Let's start off by creating some code using the blocks.

Add the following code to your project.

basic.showString("Hello!")

5 - Switch to JavaScript

Click on the JavaScript button at the top to switch your code view from Blocks to JavaScript.

This will show you your code in JavaScript. Although it looks different, it's actually the same code and does the exact same thing.


Join our club 😃

To view the remaining 5 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more