JavaScript is a lightweight, cross-platform object-oriented programming language. It's one of the three core technologies of web development along with html and css. Traditionally it was a client-side technology but these days it's widely used on the server-side as well running on Node.js. JavaScript is what made modern web development possible,
Html is for content, CSS for presentation and JavaScript for interactivity. There are two ways to add JavaScript to a html page:
# Inline Script
<script>
alert("Hello World!");
</script>
1
2
3
2
3
# Add reference to a script file
<script src="myscript.js"></script>
1
# Variables and Datatypes
var name = "LuKa"; // Strings use single or double quotes
var firstAndLastNames = 'John Silver'; // By convention camelCase is used in variable names.
var age = 26; // Number, no quotes
var isMale = true;
1
2
3
4
2
3
4
JavaScript is a dynamically typed language so you don't explicitly define a type when declaring a variable.
# Primitive types
Type | Description |
---|---|
Number | Floating point numbers for decimals and integers |
String | Sequence of characters |
Boolean | Can only hold values true of false |
Undefined | An uninitialized variable is of type Undefined |
Null | Non existing |