Javascript
Source: Dev.to
What is JavaScript?
Key concepts
- Interpreted
- Dynamical
- Scripting
- Object oriented
- Variables declaration
Variable declarations
let
let age = 30;
age = 31; // This is allowed
const
const pi = 3.14;
var
var count = 5;
var count = 10; // This is allowed
Rules for identifiers of variables
- Valid characters: letters, numbers, underscores (
_), and dollar signs ($). Numbers cannot be the first character. - Case‑sensitive:
myVariableis different frommyvariable. - Reserved words: Keywords such as
if,for,function, etc., cannot be used as variable names.
Data types
Primitive types
- Number – numeric values (integers and decimals).
- String – text enclosed in single or double quotes.
- Boolean – logical value (
trueorfalse). - Undefined – a declared variable without an assigned value.
// Output: undefined - Null – intentional absence of any value.
let empty = null; - Symbol – unique and immutable values, often used as object keys.
let sym = Symbol('unique'); - BigInt – integers larger than
Number.MAX_SAFE_INTEGER.let bigNumber = 123456789012345678901234567890n;
Non‑primitive datatypes
Non‑primitive types are objects and can store collections of data or more complex entities.
- Object – key‑value pairs.
let obj = { // properties go here }; - Array – ordered list of values.
let a = ["red", "green", "blue"]; - Function – reusable blocks of code.
function fun() { // function body }
Exploring JavaScript datatypes and variables: understanding common expressions
console.log(null === undefined);
- Expression:
null === undefined - Result:
false