JavaScript Refresh

Variables

A variable in JavaScript is a named storage location for a value. Variables are declared using the var keyword, followed by the name of the variable and an optional value assignment. Variables can be used to store values of any data type, including strings, numbers, and objects, and their values can be changed at any time. Variables are a fundamental building block of any programming language and are used to store data and make it accessible throughout your code.

TL;DR A variable is like a container where you can store a value or information. You can give the container a name, like "age" or "name", and then fill it with a specific value.
  var age = 15;
  var name = "John";
    

Function

A function in JavaScript is a piece of reusable code that performs a specific task. Functions are used to structure and organize code, making it easier to read, maintain, and test. Functions can accept arguments and return values, and they can be called multiple times with different arguments. Functions are declared using the function keyword, followed by the name of the function, a list of arguments in parentheses, and the code to be executed in curly braces.

TL;DR A function is like a recipe or a set of instructions that you can use over and over again. It takes some inputs, does something with them, and then gives you an output.
 function sayHello(name) {
  console.log("Hello, " + name + "!");
}

sayHello("John"); // outputs: "Hello, John!"