Skip to content

Instantly share code, notes, and snippets.

View rohit012's full-sized avatar

rohit chopra rohit012

View GitHub Profile
class Person {
constructor(name = '', age = 0) {
this.name = name;
this.age = age;
}
getName() {
return this.name;
}
}
var multiplyAndPrint = (num1, num2) => {
let result = num1*num2;
return result;
}
// no brackets or return is required if function has just one line
var square = num => return num*num;
const person1 = 'Bob';
const person2 = 'Fred';
//using typical string concatenation
let oldConcatStr = 'We know that ' + person1 + ' is friends with ' + person2;
//using template strings
let newConcatStr = `We know that ${person} is friends with ${person2}`
// without default params
var myFunc = function (value, options){
var value = value || 0;
var options = options || {};
// do some stuff
}
// with default params
var myFunWithDefaultParam = function (value = 0, options = {}){
// do some stuff
var bodyObj = {
height: 16,
width: 9,
breadth: 20;
};
//without destructuring
var height = bodyObj.height;
var width = bodyObj.width;
var breadth = bodyObj.breadth;
// rest param example
var multipleInputs = function (value, ...restParamValues ) {
restParamValues.forEach( function(paramVal){
// do something with paramVal
});
}
var state1 = {
val1 : 'abc',
val2: 'xyz'
};
var state2 = {
val2 : 'mno',
val3: 'xyz'
};
var value1 = 100;
let value2 = 100;
{
var value1 = 200
let value2 = 200
}
console.log(value1); // 200
console.log(value2); // 100
var myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(10);
}, 1000);
});
// handler can't change promise, just value
myPromise.then((result) => {
console.log(result);
}).catch((err) => {
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class TriesContacts {
static class Node {
HashMap<Character, Node> links = null;
boolean isFinish;