Skip to content

Instantly share code, notes, and snippets.

View sunilhari's full-sized avatar
✈️
Fight or Flight

Sunil Hari sunilhari

✈️
Fight or Flight
View GitHub Profile
//1.
var x;
x++;
console.log(x);
//Output:NaN
//2.
//Check whether a number is NaN with out using isNaN
@sunilhari
sunilhari / index.html
Created September 8, 2017 18:17 — forked from dreyescat/index.html
Webpack config to expose bundle in a variable in the global context
<html>
<head>
</head>
<body>
<script src="lib/yourlib.js"></script>
<script>
window.onload = function () {
EntryPoint.run();
};
</script>
const TIME_OUT = 1000;
function start(){
console.log("Before Set-Time-Out");
setTimeout(function(){
console.log("Inside Set-Time-Out","Exiting Set-Time-Out after "+TIME_OUT+" milliseconds");
},TIME_OUT);
console.log("Outside Set-Time-Out");
}
start();
const flatten = arr => {
let i = 0;
while (i < arr.length) {
if (Array.isArray(arr[i])) {
arr.splice(i, 1, ...arr[i]);
} else {
i++;
}
}
return arr;
"Before Set-Time-Out"
"Outside Set-Time-Out"
"Inside Set-Time-Out" -->Would be printed after 1000 milliseconds
"Exiting Set-Time-Out after 1000 milliseconds" -->Would be printed after 1000 milliseconds
//TIME_OUT = 0
Expected Output
----------------
"Before Set-Time-Out"
"Inside Set-Time-Out"
"Exiting Set-Time-Out after 0 milliseconds"
"Outside Set-Time-Out"
Actual Output
function multiply(n,n){
return n*n;
}
function square(n){
return multiply(n,n);
}
function print(n){
var squared = square(n);
// The classic AJAX call - dispatch before the request, and after it comes back
function myThunkActionCreator(someValue) {
return (dispatch, getState) => {
dispatch({type : "REQUEST_STARTED"});
myAjaxLib.post("/someEndpoint", {data : someValue})
.then(
response => dispatch({type : "REQUEST_SUCCEEDED", payload : response}),
error => dispatch({type : "REQUEST_FAILED", error : error})
);
var noError = true;
console.assert(noError,'There is an Error','in the code block');
//Output
noError = false;
console.assert(noError,'There is an Error','in the code block');
//Output
Assertion failed: There is an Error in the code block
function counter(label){
console.count(label);
}
counter('label1'); // label1 : 1
counter('label1'); // label1 : 2
counter('label1'); // label1 : 3
counter('label2'); // label2 : 1
console.count();//1