JavaScript basic syntax
| Syntax basics | |
| Variables | |
| Data types | |
| Strings |
Syntax basics
JavaScript syntax is the set of rules, conventions, and grammar for writing JavaScript code. A JavaScript program consists of a sequence of statements, which are executed one by one.
let name = "JavaScript";
let price = 10 + 5;
Variables
Variables let you store values by giving them a name. You can use var, let, or const to declare a variable.let and const are block-scoped, while var is function-scoped.
let score = 10;
const PI = 3.14;
Data types
JavaScript has dynamic types. A value's type is determined at runtime. The main types are: number, string, boolean, null, undefined, object, and symbol.
let type = typeof "hello";
console.log(type);
Strings
Strings are sequences of characters, stored as primitives. You can use single quotes, double quotes, or template literals (backticks) with embedded expressions.
let first = "Hello";
let greeting = `Hello, ${name}`;
Next: Variables and data types
Article author: Arthur Isaev