Skip to content

Commit bdef271

Browse files
Basic of JavaScript ✅
1 parent 3cf953c commit bdef271

File tree

12 files changed

+322
-0
lines changed

12 files changed

+322
-0
lines changed

2. Basic of JavaScript/1.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// To Print Output in Console
2+
3+
console.log("Hello World");
4+
5+
// Where you can use Single Qoutes or Double Qoutes
6+
7+
console.log("Working In Single Quotes");
8+
console.log("Working In Double Quotes");
9+
10+
// Output
11+
// Working In Single Quotes
12+
// Working In Double Quotes
13+
14+
// In JavaScript Semi-Colon (;) is not required after the last statement in a line. Its is Optional in JavaScript.
15+
16+
// Both Are Same
17+
// But Having Semi-Colon is a Good Practice;
18+
console.log("With Semicolon");
19+
console.log("Without Semicolon");
20+
21+
// To Run This File
22+
// node fileName.js
23+
// node 1.js
24+

2. Basic of JavaScript/10.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// 2. Function Scope
2+
console.log("FUNCTION SCOPE");
3+
4+
// This Works
5+
function scope() {
6+
const constB = "const";
7+
var varB = "var";
8+
let letB = "let";
9+
10+
console.log(varB);
11+
console.log(letB);
12+
console.log(constB);
13+
}
14+
scope();
15+
16+
/// But Not This
17+
// function scope() {
18+
// const constB = "const";
19+
// var varB = "var";
20+
// let letB = "let";
21+
22+
// }
23+
// scope();
24+
// console.log(varB);
25+
// console.log(letB);
26+
// console.log(constB);
27+
28+
// This will give a Error

2. Basic of JavaScript/11.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
function box() {
2+
var a = "i am a";
3+
console.log("Function Scope");
4+
console.log(a);
5+
}
6+
box();
7+
8+
// Here Var a is working inside function scope
9+
10+
// function box() {
11+
// var a = "i am a";
12+
// console.log("Function Scope");
13+
// }
14+
// box();
15+
// console.log(a);
16+
17+
// VAR USES
18+
19+
// 1. but if var is in a function scope ...then it can be only available in that function scope
20+
// 2. if var is in global scope ...then it can be available in all the function scope and global scope
21+
// 3. if var is in a function scope ..it will become function scope variable
22+
// 4. if var is in a function scope .. you can acces it inside that function scope at any block...inside that function scope // Having it Multiple blocks
23+
// 5. Var allows you to re declare the same variable
24+
25+
// LET USES
26+
27+
// 1. let can only be used in a block scope
28+
// 2. if let is in a function scope ...then it can be only available in that function scope
29+
// 3. if let is in global scope ...then it can be available in all the global scope but not in function scope
30+
// 4. let will dont allow you to redeclare the same variable
31+
32+
// let a = "hello;
33+
// let a = "bye"; // Error a is re declared
34+
35+
// But you can have this
36+
// let a = "hello";
37+
// a = "bye";
38+
// console.log(a) ; // This will work
39+
40+
// let a = 'hello';
41+
42+
// function box() {
43+
// // console.log(a);
44+
// console.log("Function Scope");
45+
// }
46+
47+
// console.log(a);
48+
49+
// CONST USES
50+
// const c = 'hello';
51+
// c = 'bye'; // Error c is a constant variable
52+
53+
// 1. const is a constant variable
54+
// 2. const is a block scope variable
55+
// 3. const will not work out of the function scope
56+
// 4. const will not allow you to redeclare the same variable
57+
// 5. const will not allow you to reassign the same variable
58+
// const cc = 'cc'
59+
60+
// function box() {
61+
// console.log('Const Scope');
62+
63+
// console.log(cc);
64+
// }
65+
// box();
66+
// Output: cc
67+
68+
// If const is declared outside .....you can still access inside the function
69+
// If const is declared inside .....you can not access outside the function

2. Basic of JavaScript/2.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
console.log("How To Comment in JavaScript");
2+
3+
4+
// For Single Line Comment
5+
6+
// For Multiple Line Comment
7+
// /* */
8+
9+
10+
console.log("For Multiple Line Comment Using /* */");
11+
12+
/*
13+
console.log("1");
14+
console.log("2");
15+
console.log("3");
16+
console.log("4");
17+
console.log("5");
18+
19+
*/

2. Basic of JavaScript/3.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// What is Variable ?
2+
/*
3+
Variable is a container for storing data values.
4+
Variable can be used to store data values.
5+
Variable is a name given to a memory location.
6+
We Can use the information stored in a variable to perform a task.
7+
We can use the same variable name to refer to different values.
8+
We can change the data of information later
9+
*/
10+
11+
// Declaring Variables Using var
12+
13+
var firstName = "Suhail Roushan";
14+
15+
console.log(firstName);
16+
17+
// Output : Suhail Roushan
18+
19+
// JavaScript is Case Sensitive
20+
// hello is not equal to Hello
21+
22+
firstName = "JavaScript";
23+
console.log(firstName);

2. Basic of JavaScript/4.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// By Default If you didnt declare var it will take global variable as var
2+
3+
var home = "ROOM";
4+
home = "ROOM";
5+
6+
// Both are Same
7+
8+
// By default it takes variable as global variable as var
9+
10+
// Ruling for Naming Variables
11+
// 1. Variable names can only contain letters, numbers, and underscores.
12+
// 2. Variable names are case sensitive.
13+
// 3. Variable names should not be JavaScript keywords.
14+
// Keywords are var , let , const
15+
// 4. Variable names should not start with a number.
16+
// 5. Use meaningful names in variables
17+
// 6. Use CamelCase for naming variables
18+

2. Basic of JavaScript/5.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// JavaScript is a Interpreted Language
2+
// Where you can perform Calculations
3+
4+
var add = 10 + 12
5+
console.log(add);
6+
// Output :- 22
7+
8+
var sub = 10 - 12
9+
console.log(sub);
10+
// Output :- -2
11+
12+
var mul = 10 * 12
13+
console.log(mul);
14+
// Output :- 120
15+
16+
var div = 10 / 2
17+
console.log(div);
18+
// Output :- 5
19+
20+
// In Any Programming Language % is not Percenatge its Modules
21+
// 10 % 2 = 0
22+
// The Left ones after Dividing
23+
// 10 % 3 = 1
24+
// AAA AAA AAA A
25+
// The Left one is 1 so 10%3 = 1
26+
var mod = 10 % 2
27+
console.log(mod);
28+
// Output :- 0
29+

2. Basic of JavaScript/6.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Power and Square root
2+
3+
4+
// For Power of 2
5+
6+
var a = 2
7+
console.log(a ** 3);
8+
// Output :- 8
9+
// Its 2 power 3
10+
11+
// For Square Root
12+
13+
var b = 16
14+
console.log(Math.sqrt(b));
15+
// Output :- 4
16+
// Its Square Root of 16
17+
// OR
18+
console.log(b ** 0.5);
19+

2. Basic of JavaScript/7.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// You can use _ in variable names in start or in middle
2+
// You can use $ in variable names in start or in middle
3+
4+
// All are Valid
5+
var _suhail = "Hello, world!";
6+
var suh_ail = "Hello, world!";
7+
var $suhail = "Hello, world!";
8+
var suh$ail = "Hello, world!";
9+
var suhail = "Hello, world!";
10+
11+
// Spaces are not valid in Variable names
12+
13+
// var su hail = "Hello, world!"; // Not Allowed
14+
15+
// Always use CamelCase
16+
17+
// Example : firstPerson = "Suhail";
18+
// Example : firstName = "Suhail";
19+
// Example : first_person = "Suhail";
20+
// Example : first_person_name = "Suhail";
21+
// Example : first_person_name_age = "Suhail";
22+
// Example : first_person_name_age_height = "Suhail";
23+
// Example : first_person_name_age_height_weight = "Suhail";

0 commit comments

Comments
 (0)