Skip to content

Commit 378f74c

Browse files
authored
Add files via upload
1 parent 5e3a046 commit 378f74c

20 files changed

+1340
-0
lines changed

001-Hello.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Author : Jaydatt Patel
3+
*/
4+
console.log('Hello World');

002-Variables-and-Scope.js

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Author : Jaydatt Patel
3+
variables using var, let , const------
4+
ES5: var (does not support scope)
5+
ES6: let, const (support scope)
6+
----------------------------------------------
7+
var :
8+
- You can use access this variable before declaration with undefined value.
9+
- You can declare variable using var and also You can assign values later.
10+
- You can redeclare same name variable anywhere by assining new value. If You do not assign value then it will hold previous assigned value.
11+
- It does not support scope resolution means it can access anywhere. So, declared variable in outside block {} and inside block {} with same name, both variables are same and hold same value and accessible both side. So if You modify or redeclare variable then it will make changes for all.
12+
- var variable can be access in functions if and only if function must not have redeclaration of same name variable with var, let and const. If You redeclare same variable in function with var,let or const, then it will create seperate local variable with same name only for function with assigned new value or undefined by default.
13+
14+
let :
15+
- You can not access this variable before declaration otherwise you will get error.
16+
- You can declare variable using let and also You can assign values later.
17+
- You can not redeclare same name variable within block{} but You can redeclare same name variable in other {} block.
18+
- It supports scope resolution means variable can be access only within scope block{} and inner all {} and functions. It can not be accessed out of the scope means inner block{} variables can not be access in outside block.
19+
- let variable can be access in functions if and only if function must not have redeclaration of same name variable with var, let and const. If You redeclare same variable in function with var,let or const, then it will create seperate local variable with same name only for function with assigned new value or undefined by default.
20+
21+
const :
22+
- You can not access this variable before declaration otherwise you will get error.
23+
- You can declare variable using const and you must by assigning values otherwise it will create error.
24+
- Const variable must be initialized when it was declared. You can not initialize later.
25+
- Only Primitive data type can be constant so other can modify even if You assign constant.
26+
- After assiging value, You can not modify value.
27+
- You can not redeclare same name variable within block{} but You can redeclare same name variable in other {} with assign value.
28+
- It supports scope resolution means variable can be access only within scope block{} and inner all {} and functions. It can not be accessed out of the scope means inner block{} variables can not be access in outside block.
29+
- const variable can be access in functions if and only if function must not have redeclaration of same name variable with var, let and const. If You redeclare same variable in function with var,let or const, then it will create seperate local variable with same name only for function with assigned new value.
30+
------------------------------------------------------------------
31+
* Variable names follow these rules:
32+
33+
- Variable names are case-sensitive. This means that the message and Message are different variables.
34+
- Variable names can only contain letters, numbers, underscores, or dollar signs.
35+
- Variable names cannot contain spaces.
36+
- variable names can not begin number.
37+
- Variable names can not use the reserved words.
38+
39+
*/
40+
41+
42+
//var variables
43+
console.log("----------var variables---------");
44+
45+
var vx = 10;
46+
var vy = 20;
47+
{
48+
console.log('Inner-1 {} :',vx,vy);
49+
}
50+
51+
{
52+
var vx = 11;//this variable is same in outer and inner
53+
var vz = 30;
54+
console.log('Inner-2 {} :',vx,vy);
55+
}
56+
57+
console.log('Globle-after-{} :',vx,vy,vz);
58+
59+
60+
function Vfoo1(){
61+
console.log('Vfoo1:',vx,vy,vz);
62+
}
63+
Vfoo1();
64+
65+
function Vfoo2(){
66+
//here function have same variables so it will assign as local variable.
67+
var vx = 1; //create local variable
68+
let vy = 2; //create local variable
69+
const vz = 3; //create local variable
70+
console.log('Vfoo2:',vx,vy,vz);
71+
72+
}
73+
Vfoo2();
74+
75+
console.log('Globle-after-fun :',vx,vy,vz);
76+
77+
//let letiables
78+
console.log("----------let variables---------");
79+
80+
let lx = 10;
81+
let ly = 20;
82+
{
83+
let lx = 11;// local variable with block.
84+
let lz = 30;// local variable with block.
85+
console.log('Inner {} :',lx,ly,lz);
86+
}
87+
88+
console.log("\nconsole.log('Globle-after-{} :',lx,ly,lz); //Error: lz is not defined means lz can not be access outside the block.\n")
89+
// console.log('Globle-after-{} :',lx,ly,lz); //Error: lz is not defined means lz can not be access outside the block.
90+
91+
console.log('Globle-after-{} :',lx,ly);
92+
93+
94+
function Lfoo1(){
95+
console.log('Lfoo1:',lx,ly);
96+
}
97+
Lfoo1();
98+
99+
function Lfoo2(){
100+
//here function have same variables so it will assign as local variable.
101+
var lx = 1; //Local variable
102+
let ly = 2; //Local variable
103+
const lz =3; //Local variable
104+
console.log('Lfoo2:',lx,ly,lz);
105+
106+
}
107+
Lfoo2();
108+
109+
console.log("\nconsole.log('Globle-after-fun :',lx,ly,lz); //Error: lz is not defined means lz can not be access outside the function.\n")
110+
// console.log('Globle-after-fun :',lx,ly,lz); //Error: lz is not defined means lz can not be access outside the function.
111+
console.log('Globle-after-fun :',lx,ly);
112+
113+
//const constiables
114+
console.log("----------const variables---------");
115+
116+
117+
let cx = 10;
118+
let cy = 20;
119+
{
120+
let cx = 11;// local variable with block.
121+
let cz = 30;// local variable with block.
122+
console.log('Inner {} :',cx,cy,cz);
123+
}
124+
125+
console.log("\nconsole.log('Globle-after-{} :',cx,cy,cz); //Error: cz is not defined means cz can not be access outside the block.\n")
126+
// console.log('Globle-after-{} :',cx,cy,cz); //Error: cz is not defined means cz can not be access outside the block.
127+
128+
console.log('Globle-after-{} :',cx,cy);
129+
130+
131+
function Cfoo1(){
132+
console.log('Cfoo1:',cx,cy);
133+
}
134+
Cfoo1();
135+
136+
function Cfoo2(){
137+
//here function have same variables so it will assign as local variable.
138+
var cx = 1; //Local variable
139+
let cy = 2; //Local variable
140+
const cz =3; //Local variable
141+
console.log('Cfoo2:',cx,cy,cz);
142+
143+
}
144+
Cfoo2();
145+
146+
console.log("\nconsole.log('Globle-after-fun :',cx,cy,cz); //Error: cz is not defined means cz can not be access outside the function.\n")
147+
// console.log('Globle-after-fun :',cx,cy,cz); //Error: cz is not defined means cz can not be access outside the function.
148+
console.log('Globle-after-fun :',cx,cy);

003-Variable-Strict-mode.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
3+
Author : Jaydatt Patel
4+
'use strict' :
5+
This mode allow to use variable which are defined with var,let and const. If you use variable without declare then it will give error 'ReferenceError': variable is not defined
6+
*/
7+
8+
9+
//error 'ReferenceError': variable is not defined
10+
// 'use strict';
11+
// a = 10;
12+
// console.log(a);
13+
14+
15+
//error 'ReferenceError': variable is not defined
16+
// function foo(){
17+
// 'use strict';
18+
// a = 10;
19+
// console.log(a)
20+
// }
21+
// foo();

004-Typeof-and-DataTypes.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Author : Jaydatt Patel
3+
Data types and Typeof function
4+
*/
5+
6+
var obj = typeof("Hello");
7+
console.log("\"Hello\" :", obj);
8+
9+
var obj = typeof('Hello"s world');
10+
console.log("\'Hello\"s world\':", obj);
11+
12+
var obj = typeof(`"Hello's world"`);
13+
console.log("`\"Hello's world\"` :", obj);
14+
15+
obj = typeof(10);
16+
console.log("10 :", obj);
17+
18+
obj = typeof(10n);
19+
console.log("10n:", obj);
20+
21+
obj = typeof(3.14);
22+
console.log("3.14 :", obj);
23+
24+
obj = typeof(true);
25+
console.log("true :",obj);
26+
27+
obj = typeof(1<=2);
28+
console.log("(1<=2) :",obj);
29+
30+
obj = typeof([1,2,3]);
31+
console.log("[1,2,3] :",obj);
32+
33+
obj = typeof({ city : 'Ahme'});
34+
console.log("{ city : 'Ahme'} :",obj);
35+
36+
var obj = typeof(null);
37+
console.log("NULL:", obj);
38+
39+
var obj = typeof(var_undefine);
40+
console.log("var_undefine :", obj);
41+
42+
obj = typeof(function sum(a,b) {return(a+b)});
43+
console.log("function sum(a,b) {return(a+b)} :",obj);
44+
45+
46+
obj = typeof (new Date()) //=== "object";
47+
console.log("(new Date()) :",obj);
48+
49+
obj = typeof /regex/ //=== "object";
50+
console.log("/regex/ :",obj);
51+
52+
// The following are confusing, dangerous, and wasteful. Avoid them.
53+
obj = typeof (new Boolean(true)) //=== "object";
54+
console.log("(new Boolean(true)) :",obj);
55+
obj = typeof (new Number(1)) //=== "object";
56+
console.log("(new Number(1)) :",obj);
57+
obj = typeof (new String("abc")) //=== "object";
58+
console.log("(new String(\"abc\"):",obj);
59+
60+
// Functions
61+
obj = typeof function () {} //=== "function";
62+
console.log("function () {} :",obj);
63+
obj = typeof class C {} //=== "function";
64+
console.log("class C {} :",obj);
65+
obj = typeof Math.sin //=== "function";
66+
console.log("Math.sin :",obj);

005-String_function.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* Author : Jaydatt Patel
3+
* String Functions:
4+
- string.concat(string)
5+
- str.charAt(number)
6+
- str.charCodeAt(number)
7+
- str.indexOf(char)
8+
- str.lastIndexOf(char)
9+
- str.toUpperCase()
10+
- str.toLowerCase()
11+
- str.match(string)
12+
- str.startsWith(string)
13+
- str.endsWith(string)
14+
- str.padStart(number, char)
15+
- str.padEnd(number, char)
16+
- str.substring(start index, stop index)
17+
- str.slice(start index, stop index)
18+
- str.replace(string ,string)
19+
- str.replaceAll(string ,string)
20+
- str.includes(string)
21+
- str.repeat(number)
22+
- str.trim()
23+
- str.trimStart()
24+
- str.trimEnd()
25+
- str.split(String seperator, limit)
26+
*/
27+
28+
console.log("Hello, World");
29+
console.log("Hello " + "there, " + "World");//Not space add automatically
30+
console.log("Hello","there,","World");//space add automatically
31+
32+
33+
var str = "Hello";
34+
console.log(str,'World');
35+
var year = 2023;
36+
37+
console.log(str,'World',year);
38+
39+
console.log(`${str} World ${year}`);
40+
41+
var price = 10;
42+
var VAT = 0.25;
43+
console.log(`Total: ${(price * (1 + VAT)).toFixed(2)}`);
44+
45+
46+
// string.concat(string).concat(string).concate(string)...............
47+
console.log("concate: ", str.concat('World').concat(year)); //
48+
49+
console.log(("Hello " + "there, " + "World").length);
50+
console.log("str.length : ", str.length);
51+
52+
console.log("str.charAt(1) : ", str.charAt(1));
53+
console.log("str.charCodeAt(1) : ", str.charCodeAt(1));
54+
console.log("str.indexOf('l') : ", str.indexOf('l'));
55+
console.log("str.lastIndexOf('l') : ", str.lastIndexOf('l'));
56+
57+
console.log("str.toUpperCase() : ", str.toUpperCase());
58+
console.log("str.toLowerCase() : ", str.toLowerCase());
59+
60+
//find or match string
61+
console.log("str.match('ll') : ", str.match('ll'));
62+
console.log("str.match('He') : ", str.startsWith('He'));
63+
console.log("str.match('lo') : ", str.endsWith('lo'));
64+
65+
//string padding
66+
console.log("str.padStart(10,'*') : ", str.padStart(10,'*'));
67+
console.log("str.padStart(10) : ", str.padStart(10));
68+
console.log("str.padEnd(10,'#') : ", str.padEnd(10,'#'));
69+
console.log("str.padEnd(10) : ", str.padEnd(10));
70+
71+
//substring(strart index) , substring(strart index, end index)
72+
console.log("str.substring(1) : ", str.substring(1));
73+
console.log("str.substring(1,4) : ", str.substring(1,4));
74+
75+
76+
//slice(strart index) , slice(strart index, end index)
77+
console.log("str.slice(1) : ", str.slice(1));
78+
console.log("str.slice(1,4) : ", str.slice(1,4));
79+
console.log("str.slice(-1) : ", str.slice(-1));
80+
console.log("str.slice(-1,-4) : ", str.slice(-3,-1));
81+
82+
83+
//get new string with replace characters.
84+
console.log("str.replace('l','L') : ", str.replace('l','L'));
85+
console.log("str.replaceAll('l','L') : ", str.replaceAll('l','L'));
86+
87+
console.log("str.includes('ll') : ", str.includes('ll'));
88+
console.log("str.repeat(2) : ", str.repeat(2));
89+
90+
console.log("' Hello '.trim() : ", ' Hello '.trim());
91+
console.log("' Hello '.trimStart() : ", ' Hello '.trimStart());
92+
console.log("' Hello '.trimEnd() : ", ' Hello '.trimEnd());
93+
94+
95+
//str.split(String seperator, limit) for string convert into array
96+
var str = "11-12-13-14-15";
97+
console.log("String : ", str);
98+
var values = str.split('-'); // convert string to array
99+
console.log("str.split('-') :", values);
100+
var values = str.split('-',3); // convert string to array
101+
console.log("str.split('-',3) :", values);
102+
103+
var spl = 'ho-ho-ho'.split('-');
104+
console.log("'ho-ho-ho'.split('-') : ", spl);

006-Template_literal.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Author : Jaydatt Patel
3+
Template Literal : `...text..${obj}..text..`
4+
Template literals are an alternative way of working with strings, which was introduced in the ES6 addition to the JavaScript language.
5+
6+
With template literals, an expression can be embedded in a placeholder. A placeholder is represented by ${}, with anything within the curly brackets treated as JavaScript and anything outside the brackets treated as a string
7+
*/
8+
9+
var greet = "Hello";
10+
var place = "World";
11+
console.log(greet + " " + place + " !");
12+
console.log(`${greet} ${place} !`) //display both variables using template literals
13+
14+
var multi = `Hello
15+
World
16+
${2023}
17+
!`
18+
console.log(multi);

0 commit comments

Comments
 (0)