Skip to content

Instantly share code, notes, and snippets.

View suhailgupta03's full-sized avatar
:octocat:

Suhail Gupta suhailgupta03

:octocat:
View GitHub Profile
var x = 1;
console.log(x++);
// x++ will increment the number
// after it has been printed (any operation)
// which means x will only be incremented after the
// above statement is executed
// value of x after line number 2 is executed is 2
console.log(++x);
// ++x will first increment and then
// print (or let it be used for operations)
var classNumber = 1; // Initializaiton
while(classNumber <= 12) { // Declared a condition
console.log(classNumber);
classNumber++; // Updating the state
// which is moving the student from class
// number X to X+1
}
var x = 2; // Initialization
while(x <= 100) { // Condition
if(x % 2 == 0) { // % gives the remainder
// this means that the number
// is EVEN
console.log(x);
}
x = x + 1; // Updating the state
}
var manojStudent = {
'name': 'manoj',
'age': 17,
'city': 'udaipur',
'class': '1st semster of college',
'weight': 55.67
}
console.log(manojStudent);
var manojStudent = {
'name': 'manoj',
'age': 17,
'city': 'udaipur',
'class': '1st semster of college',
'weight': 55.67
}
console.log(manojStudent['age']);
console.log(manojStudent['weight']);
var manojStudent = {
'name': 'manoj',
'age': 17,
'city': 'udaipur',
'class': '1st semster of college',
'weight': 55.67
}
for(var nameOfKey in manojStudent) {
console.log(nameOfKey, "..", manojStudent[nameOfKey]);
var topNStudents = [
'manoj',
'ramesh',
'garima',
'ashish',
'saru',
'tanya'
];
var classTimes = [
[8, 9, 8, 9], // Day 1
[1, 2, 6, 7], // Day 2
[2, 7, 8, 9] // Day 3
]
console.log(classTimes[1]);
console.log(classTimes[1][0]);
const person = {
firstName: "..",
lastName: '..',
age: 30
}
console.log(person['age']);
// We want to modify the age
for(var nameOfKey in person) {
if(nameOfKey == "age") { // If the name of key is age
// If the key is age,
var firstName = "foo";
var lastName = "bar";
var fullName = firstName + " " + lastName;
console.log(fullName);
var _fullName = `${firstName} ${lastName}`; // concatenate strings
console.log(_fullName);