JavaScript is a very popular programming language that enables many different applications: interactive websites, desktop applications and complex logic running on servers. As you can see, it is very flexible and can be used in many places.
JavaScript was created in 1995 to add interactivity to web pages. JavaScript has evolved over the years with more features and abilities and it is now one of the most popular programming languages in the world.
Although JavaScript can run in browsers alongside HTML and CSS, we will focus on using JavaScript to learn programming. HTML and CSS are not required to learn.
<aside> ⚠️
Don't confuse JavaScript with Java - they are completely different programming languages, despite their similar names.
</aside>
Watch the follow quick 5-minute video to learn more about JavaScript:
https://youtu.be/upDLs1sn7g4?si=HKyeZ3EjT_LKsSoU
Here is how a block of JavaScript code looks like:
function calculateFactorial(number) {
if (number < 0) {
return "Error: Negative numbers don't have factorials";
}
let result = 1;
for (let i = 1; i <= number; i++) {
result *= i;
}
return result;
}
const testNumber = 5;
const factorial = calculateFactorial(testNumber);
console.log(`The factorial of ${testNumber} is ${factorial}`);
console.log(`The factorial of 7 is ${calculateFactorial(7)}`);
There is a lot going on in the code above, in a couple of weeks you will be able to understand everything written in the code block above. For now,
You can run JavaScript directly in web browsers. To run JavaScript in a web application, you include it within HTML documents using the <script> tag. The browser then reads and executes the code, allowing you to manipulate web pages, respond to user actions, and create dynamic content. This makes JavaScript essential for front-end web development, enabling everything from simple form validations to complex interactive applications.
Node.js is a runtime environment that allows JavaScript to run outside of web browsers, typically on servers or your local computer. With Node.js installed on your machine, you can execute JavaScript files directly from the command line, making it possible to build server-side applications, command-line tools, and desktop applications. Node.js also provides access to system resources like the file system and network, expanding JavaScript's capabilities beyond what's possible in a browser environment.
In the core program, we will mostly use the Node.js runtime. However, we will sometimes provide you with pre-made HTML files so you can visually see your code working in the browser - rather than just the command line.
Node.js comes with a built-in REPL (Read-Eval-Print Loop). In simple words, it is a CLI environment that allows you to execute JavaScript code. Let’s give it a try:
Open a new terminal window and type node without any additional parameters. You'll see a Node.js prompt:
~$ node
Welcome to Node.js v25.1.0.
Type ".help" for more information.
>
You are now in the Node.js CLI. Here, you can run any JavaScript code. Try doing some math:
> 2+2
4
> 127/7
18.142857142857142
> 12+(11-211)*6
-1188
>
And even run JavaScript functions such as console.log from the previous week:
> console.log('Hello CLI');
Hello CLI
undefined
>
Finally, to leave the Node.JS CLI, type .exit or use theCTRL+D shortcut.
<aside> 💭
Using the Node.JS REPL is a great way to test out small pieces of code.
</aside>
Looking for even more? Check out Awesome JavaScript Learning. It contains many other tutorials about JavaScript. Some of them can be quite advanced for this time but you are welcome to take a look.
The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 **
