This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sum(a, b) { | |
let sum = a + b; | |
return sum; | |
// role of return is to "return" the | |
// value of sum to the caller | |
} | |
function isUserLoggedIn() { | |
let user = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foobar(){ | |
console.log("Inside foobar"); | |
} // helper function of printOpeningMessage | |
function printOpeningMessage() { | |
foobar(); | |
console.log("Good evening! Welcome to the restaurant.") | |
} // helper function of sum | |
function sum(a, b) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the reason we have functions is to avoid | |
// repeating code | |
function sum(arg1, arg2) { | |
var number1 = arg1; | |
var number2 = arg2; | |
var sumOfNumbers = number1 + number2; | |
console.log(sumOfNumbers); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SOME_NAME() { | |
var number1 = 100; | |
var number2 = 200; | |
var sumOfNumbers = number1 + number2; | |
console.log(sumOfNumbers); | |
} | |
SOME_NAME(); | |
// In the above statement, we are calling the function SOME_NAME() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let student = { | |
name: 'manoj', | |
age: 20, | |
course: 'cse', | |
college: 'svec', | |
parentNameList: ['girish', 'samita'], | |
}; | |
var convertedToString = JSON.stringify(student); | |
// JSON is a string representation of an object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var manish = { | |
name: 'Manish', | |
age: 25, | |
city: 'Bangalore', | |
employee: true, | |
id: 1, | |
skills: ['HTML', 'CSS', 'JS'], | |
salary: 100, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var students = [ | |
"Sudarshan", // 0th index | |
"Anish", // 1st index | |
"Chinmay", // 2nd index | |
"Rahul", // 3rd index | |
"Tushar", | |
"Syed", | |
"Sudarshan", | |
"Subhrojoti" | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arr = [1, 2, 3, 4, 5]; | |
let start = 0; | |
let end = arr.length - 1; | |
while (start < end) { | |
let temp = arr[start]; | |
arr[start] = arr[end]; | |
arr[end] = temp; | |
start++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array1 = [1, 2, 3, 4, 5]; | |
var array2 = [6, 7, 8, 9, 10]; | |
// array1[0] + array2[0] | |
// array1[1] + array2[1] | |
for(var i = 0;i < array1.length; i++) { | |
console.log(array1[i] + array2[i]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var list = [ | |
[1, 2, 3, 4], // 0th index | |
[100, 101, 102, 199], // 1st index | |
[201, 202, 203, 299], // 2nd index | |
]; // multi-dimensional array | |
// also called a matrix | |
// above is a 3x4 matrix | |
var array1 = list[0]; |