Courses
JavaScript
Introduction

JavaScript

JavaScript is a high-level, dynamic, interpreted programming language that is used primarily for creating interactive web pages and web applications. It is a client-side scripting language, which means that it runs on the user's web browser, rather than on a server.

Here are some examples of basic JavaScript code:

Example 1: Printing a message to the console

javascript
console.log("hello, world")

This code will print the message "Hello, world!" to the console, which can be accessed through the developer tools in your web browser.

Example 2: Adding numbers together

javascript
let num1 = 5;
let num2 = 10;
let sum = num1 + num2;
console.log(sum);

This code defines two variables (num1 and num2) and assigns them the values 5 and 10, respectively. It then adds these two variables together and stores the result in a third variable called sum. Finally, it prints the value of sum to the console.

Example 3: Creating a function

javascript
function greet(name) {
  console.log("Hello, " + name + "!");
}
 
greet("Alice");
greet("Bob");

This code defines a function called greet that takes a parameter called name. When the function is called, it prints a message to the console that includes the value of the name parameter. The code then calls the greet function twice, passing in the values "Alice" and "Bob" as the name parameter. This will print the messages "Hello, Alice!" and "Hello, Bob!" to the console.

These are just a few simple examples of what you can do with JavaScript. JavaScript is a powerful language with many features and capabilities, and it is an essential tool for web developers.