Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1259d71

Browse files
author
Ashish Choudhary
committed
js practice
0 parents commit 1259d71

File tree

24 files changed

+1408
-0
lines changed

24 files changed

+1408
-0
lines changed

‎.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
.DS_Store
3+
.env

‎01_Variables Data Types/01_Variables.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Variables in JavaScript
2+
// Variables are used to store data values.
3+
// There are three ways to declare variables in JavaScript: var, let, and const.
4+
// 1. var: The var keyword is used to declare a variable that can be re-assigned later.
5+
// 2. let: The let keyword is used to declare a block-scoped variable that can be re-assigned later.
6+
// 3. const: The const keyword is used to declare a block-scoped variable that cannot be re-assigned later.
7+
// Example of using var
8+
9+
var a = 10; // Re-assigning the variable
10+
var b = 20; // Re-assigning the variable
11+
var c = a + b; // Adding two variables
12+
console.log("Value of c is: " + c);
13+
14+
// Example of using let
15+
let x = 5; // Initializing a variable
16+
let y = 10; // Initializing another variable
17+
let z = x + y; // Adding two variables
18+
console.log("Value of z is: " + z);
19+
20+
// Example of using const
21+
const pi = 3.14; // Initializing a constant variable
22+
console.log("Value of pi is: " + pi);
23+
// pi = 3.14159; // This will throw an error because pi is a constant and cannot be re-assigned
24+
25+
// Data Types in JavaScript
26+
// JavaScript has dynamic typing, which means variables can hold values of any data type.
27+
// The basic data types in JavaScript are:
28+
// 1. Number: Represents both integer and floating-point numbers.
29+
let num = 42; // Integer
30+
let floatNum = 3.14; // Floating-point number
31+
32+
// 2. String: Represents a sequence of characters.
33+
let str = "Hello, World!"; // String
34+
35+
// 3. Boolean: Represents a logical value, either true or false.
36+
let isTrue = true; // Boolean value
37+
let isFalse = false; // Boolean value
38+
39+
// 4. Undefined: Represents a variable that has been declared but not assigned a value.
40+
let undefinedVar; // This variable is declared but not assigned a value
41+
console.log("Value of undefinedVar is: " + undefinedVar); // Output: undefined
42+
43+
// 5. Null: Represents an intentional absence of any value.
44+
let nullVar = null; // This variable is explicitly set to null
45+
console.log("Value of nullVar is: " + nullVar); // Output: null
46+
47+
// 6. Object: Represents a collection of key-value pairs.
48+
let person = {
49+
name: "John Doe",
50+
age: 30,
51+
isEmployed: true
52+
}; // Object with properties
53+
54+
console.log("Person object:", person);
55+
56+
// 7. Array: Represents a list-like structure that can hold multiple values.
57+
let fruits = ["Apple", "Banana", "Cherry"]; // Array of strings
58+
console.log("Fruits array:", fruits);
59+
60+
// 8. Symbol: Represents a unique and immutable value, often used as object property keys.
61+
let uniqueSymbol = Symbol("uniqueIdentifier"); // Creating a unique symbol
62+
console.log("Unique Symbol:", uniqueSymbol);
63+
64+
// 9. BigInt: Represents integers with arbitrary precision, useful for very large numbers.
65+
let bigIntValue = BigInt(1234567890123456789012345678901234567890); // BigInt value
66+
console.log("BigInt value:", bigIntValue);
67+
68+
// Summary
69+
// In JavaScript, variables can be declared using var, let, or const.
70+
// Data types include Number, String, Boolean, Undefined, Null, Object, Array, Symbol, and BigInt.
71+
// JavaScript is dynamically typed, allowing variables to hold values of any data type.
72+
// Understanding these concepts is essential for effective programming in JavaScript.
73+
// Note: Always use let or const for variable declarations in modern JavaScript to avoid issues with variable hoisting and scope.
74+
// Avoid using var unless necessary, as it has function scope and can lead to unexpected behavior.
75+
// Best practices suggest using const for variables that won't change and let for those that will.
76+
// This code provides a basic understanding of variables and data types in JavaScript.

‎01_Variables Data Types/02_index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>varibles </title>
8+
</head>
9+
10+
<body>
11+
12+
<h1>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Sunt eligendi nam velit mollitia. Vero magni molestiae
13+
nisi eaque sunt commodi, itaque porro voluptatum optio voluptate blanditiis sit delectus laborum sed veritatis
14+
quae incidunt dolore ullam neque a! Tempore, id excepturi.</h1>
15+
<script src="./02_variables_practice.js"></script>
16+
</body>
17+
18+
</html>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// var a = 10;
2+
// let b = 20;
3+
// const c = 30;
4+
// d = 40; //global variable without var, let, or const
5+
6+
// function f1() {
7+
// var x = 10; // lockl varibale
8+
// let y = 20;
9+
// lx = 6;
10+
// // console.log(x, y);
11+
// }
12+
// f1();
13+
14+
let a = 12;
15+
var b = 13;
16+
const c = a + b;
17+
// console.log(c);
18+
19+
// hosting
20+
21+
// console.log(myVar);
22+
var myVar = "Ashish Chaudhary";
23+
24+
// console.log(myLet)
25+
let myLet = "Honey Chaudhary";
26+
27+
// functions understanding hosting
28+
29+
function myFun1() {
30+
console.log(x);
31+
let x = "hello";
32+
}
33+
// myFun1(); // Cannot access 'x' before initialization
34+
35+
myFun1(); // done
36+
function myFun1() {
37+
let x = "hello";
38+
console.log(x);
39+
}
40+
41+
var myFun2 = function () {
42+
console.log(x);
43+
var x = "hello ashish";
44+
};
45+
myFun2();
46+
47+
var d = undefined
48+
49+
let s =
50+
console.log(s)

‎01_Variables Data Types/03_datatype.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// primitive data types
2+
3+
//types
4+
// 1. Number // example: 42, 3.14
5+
6+
// 2. String // example: "Hello, World!"
7+
8+
// 3. Boolean // example: true, false
9+
10+
// 4. Undefined // example: let x; // x is declared but not assigned a value
11+
12+
// 5. Null // example: let y = null;
13+
14+
// 6. BigInt // example: 1121n
15+
16+
// 7. Symbol // symbol(id)
17+
18+
// non-primitive data types
19+
// 1. Object // example: { name: "John", age: 30 }
20+
// 2. Array // example: [1, 2, 3, 4, 5]
21+
// 3. Function // example: function myFunction() { return "Hello"; }
22+
23+
let x = {
24+
name: "Ashish",
25+
age: 29,
26+
city: "Bulandshahr",
27+
};
28+
29+
console.log(x['name'])
30+
console.log(typeof x)
31+
console.log(Object.keys(x))
32+
console.log(Object.values(x))
33+
34+
function f1() {
35+
let x = "Ashish";
36+
}
37+
// console.log(typeof(f1))
38+
39+
let y = null; // output is object but null all ready null valu why show output is object
40+
// console.log(typeof y)
41+
42+
// console.log(y === null)
43+
44+
// type chacking
45+
46+
let ab = [20, 30, 40, 50];
47+
48+
let obj = {
49+
name: "honey",
50+
age: 29,
51+
};
52+
53+
console.log(typeof ab) // object
54+
console.log(typeof obj) // object
55+
56+
// Adavance checking
57+
console.log(Array.isArray(ab)) // true
58+
console.log(Array.isArray(obj)) // flase
59+
60+
// function chacking
61+
62+
function f2() {
63+
console.log("hello");
64+
}
65+
66+
console.log(typeof f2);
67+
68+
f2.yx = 10;
69+
console.log(f2.yx);
70+
71+
console.log(f2 instanceof Object);
72+
console.log(f2 instanceof Function);
73+
74+
75+
function counter() {
76+
counter.count++;
77+
}
78+
counter.count = 0;
79+
counter()
80+
counter()
81+
counter()
82+
counter()
83+
84+
console.log(counter.count)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// let a = 12;
2+
// let b = 36;
3+
4+
// const c = a / b;
5+
// console.log(Math.floor(c));
6+
7+
let v;
8+
v = 7 / 4;
9+
10+
// console.log(v);
11+
12+
let x = 5;
13+
let y = 10;
14+
let z = x--;
15+
// console.log(x, z);
16+
17+
// let arry = ["Ashish", "honey", "kevin", "codezen"];
18+
19+
// for (let i = 0; i < arry.length; i++) {
20+
// console.log(arry[i]);
21+
// }
22+
23+
// -------------------
24+
25+
let a = 10;
26+
let b = 3;
27+
28+
// console.log("Addition:", a + b);
29+
// console.log("Subtraction:", a - b);
30+
// console.log("Multiplication:", a * b);
31+
// console.log("Division:", a / b);
32+
// console.log("Modulus (remainder):", a % b);
33+
34+
// a++;
35+
// console.log("Increment:", a);
36+
37+
// b--;
38+
// console.log("Decrement:", b);
39+
40+
let sm = 10;
41+
sm += 10;
42+
// console.log(sm);
43+
44+
// > Greater then || > Less then
45+
46+
let chackAge = 20;
47+
if (chackAge >= 20) {
48+
console.log("complete");
49+
}
50+
51+
let chake = 12;
52+
let chake2 = "12";
53+
console.log(chake === 12);
54+
console.log(chake2 == 12);
55+
console.log(chake2 === 12);
56+
57+
let age1 = 20;
58+
let entery = false;
59+
60+
if (age1 >= 18 && entery) {
61+
console.log("complete");
62+
} else {
63+
console.log("not complete");
64+
}
65+
66+
let fristName = "Ashish";
67+
let lastName = "Choudhary";
68+
console.log(fristName + " " + lastName);
69+
70+
71+
let test = 2
72+
let msg = test >= 20 ? 'Adult': 'minor';
73+
console.log(msg)
74+
75+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Strict vs loose equality
2+
5 == "5"; // true
3+
5 === "5"; // false
4+
5+
// Type coercion examples
6+
0 == false; // true
7+
1 == true; // true
8+
9+
// Comparison with null/undefined
10+
null == undefined; // true
11+
null === undefined; // false
12+
13+
// String comparisons
14+
"a" < "b"; // true
15+
"Z" < "a"; // true (uppercase letters are "less than" lowercase)
16+
17+
// this is Conditional Statements
18+
function cnt(a, b) {
19+
if (a === b) {
20+
console.log(`${a} is strictly equal to ${b}`);
21+
} else if (a == b) {
22+
console.log(`${a} is loosely equal to ${b}`);
23+
} else if (a > b) {
24+
console.log(`${a} is greater equal to ${b}`);
25+
} else {
26+
console.log(`${a} is less than ${b}`);
27+
}
28+
}
29+
30+
cnt(10, 10); // acording to chnage value
31+
32+
// Comparison Functions
33+
34+
function isAdult(age) {
35+
return age >= 18;
36+
}
37+
38+
function isValidPassowrd(password) {
39+
return password !== "" && password.length >= 8;
40+
}
41+
42+
console.log(isAdult(40));
43+
console.log(isValidPassowrd('55555555'));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /