0% found this document useful (0 votes)
14 views2 pages

Javascript Beginner Notes

Success

Uploaded by

hisdeviousluv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Javascript Beginner Notes

Success

Uploaded by

hisdeviousluv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

JavaScript Beginner Notes with Examples

1. Print Something (Hello World)


console.log("Hello World");
Output:
Hello World

2. Variables
let name = "Lovely";
let age = 20;
console.log(name);
console.log(age);
Output:
Lovely
20

3. Data Types
let a = 10; // Number
let b = "Hello"; // String
let c = true; // Boolean
console.log(typeof a);
console.log(typeof b);
console.log(typeof c);
Output:
number
string
boolean

4. Operators
let x = 5;
let y = 2;
console.log(x + y);
console.log(x - y);
console.log(x * y);
console.log(x / y);
Output:
7
3
10
2.5

5. If-Else (Condition)
let marks = 80;
if (marks >= 50) {
console.log("Pass");
} else {
console.log("Fail");
}
Output:
Pass

6. Loops
for (let i = 1; i <= 5; i++) {
console.log(i);
}
Output:
1
2
3
4
5

7. Function
function greet(name) {
return "Hello " + name;
}
console.log(greet("Lovely"));
Output:
Hello Lovely

8. Array
let fruits = ["Apple", "Mango", "Banana"];
console.log(fruits[0]);
console.log(fruits[1]);
console.log(fruits.length);
Output:
Apple
Mango
3

9. Object
let person = { name: "Lovely", age: 20 };
console.log(person.name);
console.log(person.age);
Output:
Lovely
20

10. DOM Example (HTML + JS)


<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello from JS";
</script>
</body>
</html>
Output:
Hello from JS (on browser)

You might also like