Skip to content

Commit ce2eefa

Browse files
authored
Add files via upload
1 parent 5be90a3 commit ce2eefa

File tree

4 files changed

+523
-0
lines changed

4 files changed

+523
-0
lines changed

Ch 1 Practice Set.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//Ch 1 Variable -> Practice Set
2+
3+
// Q1) Create a Variable of Type String And try To Add a Number To It.
4+
5+
6+
let a = "Darshan";
7+
let b = 10;
8+
9+
console.log(a + b);
10+
11+
// Output: Darshan10
12+
13+
14+
// Q2) Use typeof Operator To Find Data-type of the First Question of the Last Answer.
15+
16+
17+
console.log(typeof (a + b));
18+
19+
// Output: String
20+
21+
22+
// Q3) Create a Const Object in JavaScript. Can You Change It to Hold A Number Latter?
23+
24+
25+
const c = {
26+
name: "Darshan",
27+
author: "CrptoMinds",
28+
isPrincipal: false
29+
}
30+
31+
c = 1;
32+
// Output: Assignment to Constant Variable -> Ans Is No
33+
34+
35+
// Q4) Try To Add a New Key In Q3 Const Object. Were You Able To Do It?
36+
37+
38+
const c1 = {
39+
name: "Darshan",
40+
author: "CrptoMinds",
41+
isPrincipal: false
42+
}
43+
44+
c1['friend'] = "Krupali";
45+
46+
//const c1 -> Point Object -> We Can Change Value Inside The Object -> We Can't Make New c1 Objact Again -> Because Of Constant
47+
console.log(c1);
48+
49+
// Output:
50+
// {
51+
// name: 'Darshan',
52+
// author: 'CrptoMinds',
53+
// isPrincipal: false,
54+
// friend: 'Krupali'
55+
// }
56+
57+
58+
// Q4) Write A JS Program To Create a Word-Meaning Dictionary Of 5 Words.
59+
60+
61+
const dict = {
62+
appreciate: "recognize the full worth of ",
63+
ataraxia: "a state of freedom from emotional disturbance",
64+
yakka: "Work, especially hard work."
65+
66+
}
67+
68+
console.log(dict.yakka);
69+
console.log(dict['yakka']);
70+
71+
// Output: Work, especially hard work.
72+
// Work, especially hard work.

Ch 1 Variable.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Variable Declaration:
2+
// To declare a variable in JavaScript:
3+
// Before ES6 -> var was used -> After ES6 -> let is used
4+
// const is used to define constant -> throughout the program value not changed
5+
6+
// Let, Const -> Used To Block Scope Variable Declaration
7+
// Var -> Globally Scoped
8+
// Let Can Be Updated But Not Re-declared
9+
//Const -> Neither Updated Nor Re-declared
10+
// Var -> Can Be Updated And Re-declared
11+
// Var & Let Is Initialized With Undefined -> Const Are Not ->
12+
var dp;
13+
let ap;
14+
const hp; //Error
15+
16+
var myVariable; // Declaration using var
17+
let anotherVariable; // Declaration using let
18+
const PI = 3.14159; // Declaration using const
19+
20+
// JS is Case Sensitive
21+
22+
// You can also declare and assign a value to a variable in a single line.
23+
24+
//JavaScript Data-Type
25+
//Object Is Non Primitive Data-Type
26+
// Primitive -> Null, Number, String, Symbol, Undefined, Boolean, Bigint -> Fundamental Data-Type -> nn bb ss u
27+
28+
29+
let y = BigInt("265");
30+
let x = Symbol("I Am Symbol");
31+
let s = null; //Define Null
32+
33+
// Type
34+
console.log(typeof x);
35+
36+
//Object -> In Python -> Dictionary
37+
//ES6 -> ECMAScript -> Modern JavaScript
38+
const item = {
39+
name: "CryptoMinds",
40+
age: "12"
41+
//Key: Value
42+
}
43+
44+
console.log(item["age"]); //Look Up
45+
46+
//Scope -> Alt + Click -> Multiple Cursor In Replit
47+
//var
48+
49+
var b = 11;
50+
var b = 13; // Allow To Use
51+
52+
{
53+
var b = 15;
54+
console.log(b);
55+
}
56+
console.log(b);
57+
58+
//Output
59+
// 15
60+
// 15
61+
62+
//let
63+
64+
let b = 11;
65+
66+
{
67+
let b = 15;
68+
console.log(b);
69+
}
70+
console.log(b);
71+
72+
//Output
73+
// 15
74+
// 11
75+
76+
77+
let c = 16;
78+
c = 17; //Update
79+
80+
81+
let d = 16;
82+
let d = 17; //Error
83+
84+
85+
86+
87+
88+
89+
var myNumber = 42;
90+
let myString = "JavaScript";
91+
const myConstant = true;
92+
93+
// Variable Naming:
94+
// JavaScript variable names can include letters, digits, underscores, and dollar signs. They must start with a letter, underscore, or dollar sign (but not a digit). JavaScript is case-sensitive, so myVariable and myvariable are considered different variables.
95+
96+
var firstName;
97+
let age;
98+
const PI = 3.14;
99+
100+
101+
102+
// Better Practice to use let and Const
103+
// Mostly Use Const
104+
// JS Allow to Change Variable Type In Run Time -> Only One
105+
106+
107+
function myFunction() {
108+
var x = 10; // Function-scoped variable
109+
if (x > 5) {
110+
let y = 20; // Block-scoped variable
111+
console.log(x + y);
112+
}
113+
console.log(x); // Accessible
114+
console.log(y); // Error: y is not defined
115+
}
116+
117+
118+
// Variable Hoisting:
119+
// JavaScript has a concept called "hoisting," where variable and function declarations are moved to the top of their respective scopes during the compilation phase. Variables declared with var are hoisted but are not initialized until the line where they are defined. This can sometimes lead to unexpected behavior.
120+
121+
122+
console.log(x); // Undefined
123+
var x = 10;
124+
125+
126+
// Variable Constants:
127+
// Variables declared with const are constants, meaning their value cannot be reassigned once it is set. However, it's important to note that const does not make objects or arrays immutable. It only prevents the reassignment of the variable itself.
128+
129+
130+
const PI = 3.14;
131+
PI = 3.14159; // Error: Assignment To Constant Variable
132+
133+
const myArray = [1, 2, 3];
134+
myArray.push(4); // Valid, Since The Array Itself Is Mutable
135+
136+
// Conclusion:
137+
// JavaScript variables play a crucial role in storing and manipulating data within a program. By understanding variable declaration, assignment, naming, scope, and the differences between var, let, and const, developers can effectively work with variables to create dynamic and interactive JavaScript applications.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Ch 2 Expression & Conditional Statement Practice Set
2+
3+
4+
// Q1) Use Logical Operator To Find Whether The Age Of a Person Lies Between 10 & 20.
5+
6+
let age = 15;
7+
8+
if (age >= 10 && age <= 20) {
9+
console.log("The age is between 10 and 20.");
10+
} else {
11+
console.log("The age is not between 10 and 20.");
12+
}
13+
14+
15+
// Q2) Demonstrate The Use Of Switch Statement In JS With an Example.
16+
17+
let day = 3;
18+
let dayName;
19+
20+
switch (day) {
21+
case 1:
22+
dayName = "Monday";
23+
break;
24+
case 2:
25+
dayName = "Tuesday";
26+
break;
27+
case 3:
28+
dayName = "Wednesday";
29+
break;
30+
case 4:
31+
dayName = "Thursday";
32+
break;
33+
case 5:
34+
dayName = "Friday";
35+
break;
36+
case 6:
37+
dayName = "Saturday";
38+
break;
39+
case 7:
40+
dayName = "Sunday";
41+
break;
42+
default:
43+
dayName = "Invalid day";
44+
}
45+
46+
console.log(dayName);
47+
48+
49+
// Q3) Write JS Program To Find Whether the Number Is Divisible By 2 And 3.
50+
51+
let number = 12;
52+
53+
if (number % 2 === 0 && number % 3 === 0) {
54+
console.log(number + " is divisible by both 2 and 3.");
55+
} else {
56+
console.log(number + " is not divisible by both 2 and 3.");
57+
}
58+
59+
60+
// Q4) Print "You Can Drive" Or "You Can't Drive" Based On Age Being Greater Than 18 Using Ternary Operator
61+
62+
let age = 20;
63+
let canDrive = age > 18 ? "You can drive." : "You can't drive.";
64+
65+
console.log(canDrive);
66+
67+

0 commit comments

Comments
 (0)