Description and basic syntax
Last updated
Was this helpful?
Last updated
Was this helpful?
JavaScript is arguably the most popular programming language.
JavaScript is a programming language that conforms to the ECMAScript specification. JavaScript is high-level, often just-in-time compiled, and multi-paradigm. It has curly-bracket syntax, dynamic typing, prototype-based object-orientation, and first-class functions.
More than this, JavaScript is single threaded, non-blocking, asynchronous.
Along with HTML and CSS, JavaScript (often abbreviated as JS) is one of the three pillars of the World Wide Web and was started as a way to add interactivity to web pages. However, its role has expanded over the years.
The biggest leap in JavaScript's evolution was the ES6 iteration which will be detailed starting with the Advanced Javascript section.
As well as many other languages, Javascript supports, but it is not limited to the following programming concepts:
Variables of Data Types (ex: Booleans, Numbers, Strings)
Operators (ex: Arithmetic, Assignment, Comparison, Logical, Bitwise)
Structural types:
Functions
Objects
Conditional statements and loops
Inline
Directly in the HTML file between script
tags
Using external .js
files
Functions are named blocks of reusable code. (Actually starting with ES6, functions can also be anonymous)
Functions can return a desired value; the default returned value in case the return
statement is missing is undefined
JavaScript applies function scoping for its variables.
We can only use the arguments inside the function, they are not accessible from the outside.
We can also declare local variables that have the same scope as parameters.
Variables from outside the function are accessible only if declared in the enclosing scope
Shorter syntax for simple conditions: condition ? exprIfTrue : exprIfFalse
Basic for
loop has the following general syntax:
for ([initialExpression]; [conditionExpression]; [incrementExpression]) { statement
}
The following example shows the difference between a for...of
loop and a for...in
loop. While for...in
iterates over property names, for...of
iterates over property values.
A while
statement executes its statements as long as a specified condition evaluates to true