JavaScript is a powerful script programming language that commonly used for web development (it can also be used for other purposes too, but web development is the most popular use). With endless support libraries and frameworks, JavaScript is growing strongly.
Ctrl+Shift+I
/F12
To declare your variables, you must use keywords (var
, let
, or const
). For example:
const num = 1; // declare variable num with initial value of 1.
console.log(num); // Print 1 to the console
const maybeNum; // declare variable maybeNum without initial value. You must assign a value afterward before running the code.
Here are some key differences between these 3 keywords:
var | let | const | |
---|---|---|---|
Version supported | Beginning of JS | ES6+ | ES6+ |
Can reassign value? | Yes | Yes | No |
Can redeclare variables? | Yes | No | No |
Scope | Global, Function | Function, Block | Function, Block |