Skip to content

Instantly share code, notes, and snippets.

View satyam-dev's full-sized avatar

Satyam satyam-dev

  • New Delhi, India
View GitHub Profile
// Understanding apply, call and bind
// call
const person = {
first: 'Satyam',
last: 'Saluja'
}
console.log(person.first + ' ' + person.last);
// reduce
function myReduce(callback, initial) {
let acc = (initial === undefined) ? undefined : initial;
for (let i = 0; i < this.length; i++) {
if (acc !== undefined) {
acc = callback(acc, this[i], i, this);
} else {
acc = this[i];
}
header p:hover,
main p:hover,
footer p:hover {
color: red;
cursor: pointer;
}
function display(data){
console.log(data)
}
function printHello(){
console.log(“Hello”);
}
function blockFor300ms(){
/* blocks js thread for 300ms with long for loop */
}
function sayHello() {
console.log('Hello!');
}
function sayBye() {
console.log('Bye!');
}
setTimeout(sayHello, 1000);
setTimeout(sayBye, 2000);
getData(function(x){
getMoreData(x, function(y){
getMoreData(y, function(z){
...
});
});
});
function fetchUsers(userId, callback) {
// call some magical API
callback(user);
}
// calling the above function
fetchUsers('some_id', (user) => {
console.log('My user object', user);
});
console.log('Beginning of code sample');
document.getElementById('mybutton').addEventListener('click', () => {
console.log("You clicked the button!")
});
console.log('End of code sample');
const num1 = 1;
const num2 = 2;
console.log(`Sum of ${num1} and ${num2} is `, num1+num2);
@satyam-dev
satyam-dev / drawer.dart
Created February 1, 2020 12:53
Drawer navigation option
return Scaffold(
appBar: AppBar(title: Text(title)),
body: Center(child: Text('Hola thy friend!')),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(