JavaScript is used to:
JavaScript runs in the browser and can also run on servers using tools like Node.js.
To add JavaScript to an HTML file, use the
Example:
Variables store data that can change, while constants hold data that won’t change.
Declaring Variables:
JavaScript has the following data types:
"Hello"
42
true
or false
{key: value}
[1, 2, 3]
Example:
Operators are used to perform operations.
+
, -
, *
, /
, %
==
, ===
, !=
, &&
, ||
, !
Example:
Control the flow of your program based on conditions.
Example:
Loops let you repeat code blocks.
For Loop:
While Loop:
Functions are reusable blocks of code.
Example:
JavaScript can interact with HTML elements via the Document Object Model (DOM).
Example:
2. Random Number Generator: