Introductory JavaScript
Introductory JavaScript
What is JavaScript?
• JavaScript runs in the browser and is used for both front-end and back-end
development (Node.js).
Writing JavaScript
<script>
console.log("Hello, JavaScript!");
</script>
console.log("Hello, JavaScript!");
And linked in HTML like this:
<script src="script.js"></script>
Comments in JavaScript
/*
This is a
multi-line comment
*/
Declaring Variables
Type Example
Array [1, 2, 3]
null null
undefined undefined
Input and Output
// Output
// Input
Operators in JavaScript
+ a+b Addition
- a-b Subtraction
* a*b Multiplication
/ a/b Division
% a%b Modulus
!= a != b Not equal
Conditional Statements
} else {
}
Loops in JavaScript
For Loop
}
While Loop
let count = 0;
console.log(count);
count++;
Functions
function greet() {
console.log("Hello!");
function add(a, b) {
return a + b;
console.log(colors.length); // Output: 3
console.log(colors);
Objects in JavaScript
let person = {
name: "Alice",
age: 25,
greet: function() {
};
<script>
function sayHello() {
alert("Hello, JavaScript!");
</script>
Example Program: Simple Calculator