hello.js

var please = require('share');
console.log('thank you');

NEW !!!

Thursday, 3 March, 2016 UTC

Helpful Console Logging Tricks

Using conditional breakpoints to log data If you wanted to log to the console a value each time a function is called, you can use conditional break points to do this. Open up your dev tools, find the function where you’d like to log data to the console ... more


Friday, 26 February, 2016 UTC

Easiest way to extract unix timestamp in JS

We frequently need to calculate with unix timestamp. There are several ways to grab the timestamp. For current unix timestamp easiest and fastest way is const timestamp = Date.now(); or const timestamp = new Date().getTime(); To get unix timestamp of ... more


Friday, 26 February, 2016 UTC

Easiest way to extract unix timestamp in JS

We frequently need to calculate with unix timestamp. There are several ways to grab the timestamp. For current unix timestamp easiest and fastest way is const dateTime = Date.now(); const timestamp = Math.floor(dateTime / 1000); or const dateTime = new ... more


Wednesday, 17 February, 2016 UTC

Reduce builtin function usage

As written in documentation the reduce() method applies a function against an accumulator and each value of the array (from left-to-right) to reduce it to a single value. reduce() reduce() function accepts 2 parameters (M: mandatory, O: optional): (M) ... more


Tuesday, 16 February, 2016 UTC

Basics declarations

Below, different ways to declare variables in JavaScript. Comments and console.log should be enough to explain what's happening here: var y, x = y = 1 //== var x; var y; x = y = 1 console.log('--> 1:', `x = ${x}, y = ${y}`) // Will print //--> ... more


Tuesday, 16 February, 2016 UTC

Detect document ready in pure JS

The cross-browser way to check if the document has loaded in pure JavaScript is using readyState . if (document.readyState === 'complete') { // The page is fully loaded } You can detect when the document it's ready... let stateCheck = setInterval(() ... more


Tuesday, 16 February, 2016 UTC

Basics declarations

Below, different ways to declare variables in JavaScript. Comments and console.log should be enough to explain what's happening here: var y, x = y = 1 //== var x; var y; x = y = 1 console.log('--> 1:', `x = ${x}, y = ${y}`) // Will print //--> ... more


Monday, 15 February, 2016 UTC

Calculate the Max/Min value from an array

The built-in functions Math.max() and Math.min() find the maximum and minimum value of the arguments, respectively. Math.max(1, 2, 3, 4); // 4 Math.min(1, 2, 3, 4); // 1 These functions will not work as-is with arrays of numbers. However, there are some ... more


Monday, 15 February, 2016 UTC

Detect document ready in pure JS

The cross-browser way to check if the document has loaded in pure JavaScript is using readyState . if (document.readyState === 'complete') { // The page is fully loaded } You can detect when the document it's ready... let stateCheck = setInterval(() ... more


Sunday, 14 February, 2016 UTC

Calculate the Max/Min value from an array

There are two methods to find Max and Min numbers from an argument list of numbers but they does not support Arrays natively. Math.max(1, 2, 3, 4); // 4 Math.min(1, 2, 3, 4); // 1 apply() allows you to use built-ins functions to find Max Min value in ... more


Saturday, 13 February, 2016 UTC

Know the passing mechanism

JavaScript is pass-by-value, technically. It is neither pass-by-value nor pass-by-reference, going by the truest sense of these terms. To understand this passing mechanism, take a look at the following two example code snippets and the explanations. ... more


Saturday, 13 February, 2016 UTC

Know the passing mechanism

JavaScript is pass-by-value, technically. It is neither pass-by-value nor pass-by-reference, going by the truest sense of these terms. To understand this passing mechanism, take a look at the following two example code snippets and the explanations. ... more


Friday, 12 February, 2016 UTC

Use destructuring in function parameters

I am sure many of you are already familiar with the ES6 Destructuring Assignment. Did you know that you can also use it in function parameters? var sayHello = function({ name, surname }) { console.log(`Hello ${name} ${surname}! How are you?`); }; sayHello({ ... more


Friday, 12 February, 2016 UTC

Use destructuring in function parameters

I am sure many of you are already familiar with the ES6 Destructuring Assignment. Did you know that you can also use it in function parameters? var sayHello = function({ name, surname }) { console.log(`Hello ${name} ${surname}! How are you?`); }; sayHello({ ... more


Thursday, 11 February, 2016 UTC

Preventing Unapply Attacks

By overriding the builtin prototypes, attackers can rewrite code to expose and change bound arguments. This can be a serious security hole that works by exploting a polyfill es5 methods. // example bind polyfill function bind(fn) { var prev = Array.prototype.slice.call(arguments, ... more


Wednesday, 10 February, 2016 UTC

Array average and median

The following examples will be based on the following array: let values = [2, 56, 3, 41, 0, 4, 100, 23]; To get the average, we have to sum up numbers and then divide by the number of values. Steps are: - get the array length - sum up values - get the ... more


Wednesday, 10 February, 2016 UTC

Using JSON.Stringify

Let's say there is an object with properties "prop1", "prop2", "prop3". We can pass additional params to JSON.stringify to selectively write properties of the object to string like: var obj = { 'prop1': 'value1', 'prop2': ... more


Tuesday, 9 February, 2016 UTC

Advanced Javascript Properties

It is possible to configure object properties in Javascript for example to set properties to be pseudo-private or readonly. This feature is available since ECMAScript 5.1, therefore supported by all recent browsers. To do so, you need to use the method ... more


Monday, 8 February, 2016 UTC

Advanced Javascript Properties

It is possible to configure object properties in Javascript for example to set properties to be pseudo-private or readonly. This feature is available since ECMAScript 5.1, therefore supported by all recent browsers. To do so, you need to use the method ... more


Sunday, 7 February, 2016 UTC

Flattening multidimensional Arrays in JavaScript

These are the three known ways to merge multidimensional array into a single array. Given this array: var myArray = [[1, 2],[3, 4, 5], [6, 7, 8, 9]]; We wanna have this result: [1, 2, 3, 4, 5, 6, 7, 8, 9] Solution 1: Using concat() and apply() var myNewArray ... more


Sunday, 7 February, 2016 UTC

Flattening multidimensional Arrays in JavaScript

These are the three known ways to merge multidimensional array into a single array. Given this array: var myArray = [[1, 2],[3, 4, 5], [6, 7, 8, 9]]; We wanna have this result: [1, 2, 3, 4, 5, 6, 7, 8, 9] Solution 1: Using concat() and apply() var myNewArray ... more


Saturday, 6 February, 2016 UTC

Deduplicate an Array

Primitives If an Array only contains primitive values, we can deduplicate it by only using the filter and indexOf methods. var deduped = [ 1, 1, 'a', 'a' ].filter(function (el, i, arr) { return arr.indexOf(el) === i; }); console.log(deduped); // [ 1, ... more


Saturday, 6 February, 2016 UTC

Deduplicate an Array

Primitives If an Array only contains primitive values, we can deduplicate it by only using the filter and indexOf methods. var deduped = [ 1, 1, 'a', 'a' ].filter(function (el, i, arr) { return arr.indexOf(el) === i; }); console.log(deduped); // [ 1, ... more


Friday, 5 February, 2016 UTC

Observe DOM changes in extensions

MutationObserver is a solution to listen DOM changes and do what you want to do with elements when they changed. In following example there is some emulation of dynamic content loading with help of timers, after first "target" element creation ... more


Thursday, 4 February, 2016 UTC

Assignment Operators

Assigning is very common. Sometimes typing becomes time consuming for us 'Lazy programmers'. So, we can use some tricks to help us and make our code cleaner and simpler. This is the similiar use of x += 23; // x = x + 23; y -= 15; // y = y - 15; z *= ... more


Wednesday, 3 February, 2016 UTC

Implementing asynchronous loop

Let's try out writing an asynchronous function which prints the value of the loop index every second. for (var i=0; i<5; i++) { setTimeout(function(){ console.log(i); }, 1000); } The output of the above programs turns out to be > 5 > 5 > ... more


Wednesday, 3 February, 2016 UTC

Implementación de bucle asíncrono.

Vamos a probar a escribir una función asíncrona que imprime el valor del índice del bucle cada segundo. for (var i=0; i<5; i++) { setTimeout(function(){ console.log(i); }, 1000); } La salida de los script antes mencionados resulta ser > 5 > ... more


Wednesday, 3 February, 2016 UTC

实现异步循环

让我们试着写一个异步方法,每秒打印一次循环的索引值。 for (var i=0; i<5; i++) { setTimeout(function(){ console.log(i); }, 1000 * (i+1)); } 如上程序的输出为: > 5 > 5 > 5 > 5 > 5 这明显是有问题的。 原因 每次时间结束(timeout)都指向原始的 i ,而并非它的拷贝。所以,for循环使 i 增长到5,之后 timeout 运行并调用了当前 i 的值(也就是5)。 ... more


Tuesday, 2 February, 2016 UTC

Create Range 0...N easily using one line

Below is the line with which we can create 0...N range. Array.apply(null, {length: N}).map(Number.call, Number); Lets break down this line into parts.We know how "call" function works in javascript.So in "call" first argument will ... more


Monday, 1 February, 2016 UTC

Map() to the rescue; adding order to Object properties

Object properties order An object is a member of the type Object. It is an unordered collection of properties each of which contains a primitive value, object, or function. A function stored in a property of an object is called a method. ECMAScript Take ... more