Name: JavaScript
Creator(s): Brendan Eich
Date: December 4, 1995
Website: ECMA International
JavaScript often abbreviated as JS, is a programming language that conforms to the ECMAScript specification. JavaScript is high-level, often just-in-time compiled and multi-paradigm. It has dynamic typing, prototype-based object-orientation and first-class functions. Alongside HTML and CSS, JavaScript is one of the core technologies of the World Wide Web. Over 97% of websites use it client-side for web page behavior, often incorporating third-party libraries. All major web browsers have a dedicated JavaScript engine to execute the code on the user's device.
Variables in JavaScript can be denoted with the keyword var
or the keyword let
. Using semicolons at the end of lines is optional.
var language = "JavaScript"
let awsome = true;
Like many other languages If/Else statements in JavaScript use brackets around the condition and curly braces around the body.
if (true) {
console.log("True!")
} else {
console.log("False!")
}
The JavaScript for loop follows the initial/condition/after style shown below.
for (var i = 0; i < 10; i++) {
console.log(i)
}
Functions in JavaScript are denoted with the keyword function
followed by the function name and a list of arguments. Arguments can have optional placeholders as shown below.
function addTwoNumbers(num1, num2=42) {
return num1 + num2
}
Classes in JavaScript are denoted with the keyword class
and the constructor method can be defined with the reserved name constructor
. New instances of a class are initialized with the keyword new
.
class Polygon {
constructor(width, height) {
this.width = width
this.height = height
}
}
var polygon = new Polygon(10, 20)
console.log("The area of the polygon is: " + polygon.width * polygon.height)