What you Should already know
This guide assumes you already have some basic knowledge of the following:
- A general understanding of how the internet and the World Wide Web work.
- Good working knowledge of HTML (HyperText Markup Language) and how a web page is structured.
- Some programming experience. If you are new to programming, try one of the beginner tutorials first and come back.
JavaScript and Java
JavaScript and Java are similar in some ways but very different in others. JavaScript resembles Java in its basic expression syntax and control flow, but it has no static types and no compile step. Java code is compiled and runs on the JVM, while JavaScript runs directly in the browser or in Node.js.
In contrast to Java's compile-time system built on class declarations, JavaScript supports a runtime system based on a small number of data types: numbers, strings, booleans, objects and functions. JavaScript uses prototype-based inheritance instead of class-based inheritance, although modern JavaScript also has a class keyword on top of prototypes. Functions are first-class values, so they can be stored in variables, passed to other functions and returned from them. This makes JavaScript flexible and easy to start with.
Java is a class-based language designed for fast execution and type safety. Every value has a type that is checked before the program runs, and objects are built from classes. JavaScript is more relaxed: variables can hold any type, and objects can get new properties at any time. That freedom makes JavaScript quick to write, but it also means you must test your code carefully.
Hello world
Here's an example of a "Hello, World!" function in various programming languages:
public class HelloWorld {
public static void main(String[]
args) {
System.out.println("Hello,
World!");
}
}
These examples show how to define and call a "Hello, World!" function in different programming languages. The function's purpose is to help beginners get started and understand the basic syntax of a language.
Variables
A variable is a named container that stores a value. In JavaScript you declare variables with let, const or var. Use const for values that never change, let for values that do, and avoid var in modern code.
After declaring a variable, you can assign a value to it. This is done using the assignment operator (=). The assigned value must be of the same data type as the variable.
In this example, age, name, and height are variables that store different types of data. They are used in calculations, string concatenation, and printing.