Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 97b8e82

Browse files
first commit
0 parents  commit 97b8e82

File tree

9 files changed

+184
-0
lines changed

9 files changed

+184
-0
lines changed

js-practice/arrays.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// arrays are not type-specific in js
2+
// different data types can be stored in an array
3+
let a = [1,2,3,4] // valid
4+
// data can be accessed using the index of the element
5+
console.log(a[3]) // printing 4 on console
6+
a = [1,"sun",["a","b"],{"name":"js"}] //valid
7+
console.log(a[2][1]) // printing b on console
8+
a = [1,2,3,4]
9+
// Push - adding data in the end
10+
// Unshift - adding element in the beginning
11+
// Pop - removing element from the last
12+
// Shift - remove an element from the beginning
13+
a.push(5) // [1,2,3,4,5]
14+
a.unshift(0) // [0,1,2,3,4,5]
15+
a.pop() // [0,1,2,3,4]
16+
a.shift() // [1,2,3,4]
17+
a.sort() // will sort data in an array

js-practice/doWhile.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let i=1;
2+
while(i<5){
3+
// console.log(i)
4+
i++;
5+
}
6+
7+
i=20;
8+
do{
9+
console.log("i value::"+i)
10+
i++;
11+
}
12+
while(i<1);

js-practice/forLoop.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
for(let i=1;i<5;i++){
2+
// console.log(i)
3+
}
4+
5+
let carDetails = {
6+
name:"i20",
7+
make:"2023",
8+
cost:"300000"
9+
}
10+
11+
for(let key in carDetails){
12+
// console.log(key +"::"+carDetails[key])
13+
}
14+
15+
let months = ["jan","feb","mar","apr"]
16+
17+
for(let month in months){
18+
// console.log(months[month])
19+
}
20+
21+
let numbers = [10,20,30,40]
22+
let total=0
23+
numbers.forEach(num=>{total+=num})
24+
console.log(total)

js-practice/ifElseIf.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
let num1 = 20
3+
let num2 = 30
4+
5+
console.log("num1::"+num1)
6+
console.log("num2::"+num2)
7+
8+
if(num1<num2)
9+
console.log("num1 is less than num2")
10+
11+
if(num1>num2)
12+
console.log("num1 is greater than num2")
13+
14+
if(num1<num2){
15+
console.log("num1 is less than num2")
16+
}else if(num1>num2){
17+
console.log("num1 is greater than num2")
18+
}else if(num1==num2){
19+
console.log("num1 is equal to num2")
20+
}else{
21+
console.log("numbers cannot be compared")
22+
}

js-practice/mathOperations.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let num1 =10
2+
let num2 =20
3+
4+
console.log(num1+num2)
5+
console.log(num1-num2)
6+
console.log(num1*num2)
7+
console.log(num1/num2)
8+
console.log(num1%num2)
9+

js-practice/objects.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Objects are complex data types in js.
2+
// objects are similar to hash in java like key value pair
3+
let car = {
4+
type:"Hyundai",
5+
make:"2022",
6+
cost:1000000
7+
}
8+
// Object details can be accessed in two ways
9+
console.log(car.type)
10+
console.log(car["type"])
11+
// New property can be added in two ways
12+
car.number = 1234
13+
car["number"] = 1234
14+
// delete is used to remove property form the object
15+
delete car.make
16+
// now car will have 3 keys
17+
let car = {
18+
type:"Hyundai",
19+
number:1234,
20+
cost:1000000
21+
}

js-practice/switchCase.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
let day = 3
2+
3+
switch (day) {
4+
case 1:
5+
console.log("Day is Sunday")
6+
break;
7+
case 2:
8+
console.log("Day is Monday")
9+
break;
10+
case 3:
11+
console.log("Day is Tuesday")
12+
break;
13+
case 4:
14+
console.log("Day is Wednesday")
15+
break;
16+
case 5:
17+
console.log("Day is Thursday")
18+
break;
19+
case 6:
20+
console.log("Day is Friday")
21+
break;
22+
case 7:
23+
console.log("Day is Saturday")
24+
break;
25+
default:
26+
console.log("given day is not in between 1-7")
27+
28+
}
29+
30+

js-practice/variables.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//Let, Var and cost are the three ways to declare variables in JS
2+
// Let is been introduced in ES6
3+
// JS is a Dynamically typed language
4+
let i = 20 // i is initialized as number
5+
i="Hello" // it can be assigned with a string
6+
i = [1,2,3,4] // can be re-assigned to an array
7+
// similar in case of var
8+
var j = 20 // i is initialized as number
9+
j="Hello" // it can be assigned with a string
10+
j = [1,2,3,4] // can be re-assigned to an array
11+
// variables declared with let are only available inside the block where the variable is declared
12+
// Ex
13+
function let_scope_Ex(){
14+
if(true){
15+
let let_variable = "Hello World"
16+
console.log("inside block scope::"+let_variable)
17+
}
18+
19+
console.log("Outside Block scope::"+let_variable) // throw an error
20+
21+
22+
}
23+
function var_scope_Ex(){
24+
if(true){
25+
let var_variable = "Hello World"
26+
console.log("inside block scope::"+var_variable)
27+
}
28+
console.log("Outside Block scope::"+var_variable) // print Hello world without any error
29+
}
30+
31+
32+
// Const keyword is used to declare constants
33+
// variables declared with const keyword cannot be reassigned
34+
35+
36+
const PI = 3.14
37+
PI = 3.1428 // this will throw an error as const re-assigned with a new value

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "w2a-cypress",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "",
11+
"license": "ISC"
12+
}

0 commit comments

Comments
 (0)