Writing Custom Callback for ajax

In this post, I will share how could you use callbacks to write efficient and maintainable ajax using callbacks. Promises can also be use but here i will discuss it with callbacks.
The definition of callback is
A reference to executable code, or a piece of executable code, that is passed as an argument to other code. 
Let's see an example code of custom callback,
function test(param1, param2, callback) {
    alert('Started function.\n\nIt has: ' + param1 + ', ' + param2);
    callback();
}
test('foo', 'bar', function() {
    alert('Finished function.');
});

Check if object value exists and set new value for object key | Code optimization

Recently I have seen a code in the production that is
 if (!angular.isUndefined(newVal)) {
   if(!angular.isUndefined(newVal.min)){
     $scope.dataPoints.min = newVal.min;
   }
   if(!angular.isUndefined(newVal.max)){
     $scope.dataPoints.max = newVal.max;
   }
   if(!angular.isUndefined(newVal.yellowRangeMin)){
     $scope.dataPoints.yellowRangeMin = newVal.yellowRangeMin;
   }
   if(!angular.isUndefined(newVal.yellowRangeMax)){
     $scope.dataPoints.yellowRangeMax = newVal.yellowRangeMax;
   }
   if(!angular.isUndefined(newVal.redRangeMin)){

Returning Promise in a function

Hi guys, Today I will show you how can you return a promise in the function. Let see an example
function testPromise() {
  return new Promise( function(resolve, reject) {
    resolve("Test Result");
  });
}

testPromise.then(function(d){
  console.log(d);
});
It will give an error TypeError: testPromise.then is not a function the issue is that the function doesn't have a then property, but the promise it returns does. so correct answer will be,
function testPromise() {
  return new Promise( function(resolve, reject) {
    resolve("Test Result");
  });
}

Ajax in React

Today I will share you the example that how ajax call can be done in react. You can choose any HTTP library but i will choose the axios. Here is the example this code will take reddit aww subreddit text and images from subreddt aww(cute pictures of animals). Here is the following code
import React from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';

class AjaxDemo extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            posts: []
        };
    }

    componentDidMount() {

Creating Basic Text Price Filter in React | Learning purpose

Recently,I have started learning the Reactjs and written small code that takes input value from user and return the values which are greater then number from that list. I have used the create-react-app boiler plate code. React bootstrap is also used in for it. Here is my code, code describes how to handle states and how can use react components with Es6 power capability.
import React from 'react';
import ReactDOM from 'react-dom';
import { Component } from 'react';
import './index.css';
import { Button } from 'react-bootstrap';
import { FormControl } from 'react-bootstrap';

Merging array of Objects in Javascript | Es6

We can use reduce function to merge array of objects in JavaScript, but you have to look out for a gotcha that is to provide an initialValue = {}; Here is the following code
function unproperMergeArrayofObjects(array){
    try{
       return array.reduce((a,b)=>Object.assign(a,b));
    }
    catch (err) {
        console.error(err);
        return null;
    }

}
function propermergeArrayofObject(array) {
    var initialValue={};
    return array.reduce((a,b)=>Object.assign(a,b),initialValue);
}

console.log('unproper',unproperMergeArrayofObjects([]));
var a={a:1};

Object Spread Operator | Cloning Object in Javascript

For cloning Javascript objects you can use following code,
var obj = { a: 1 };
var copy = Object.assign({}, obj);
console.log(copy); // { a: 1 }
A new term has been introduced the Object Spread Operator. It's not yet an official part of the language, but it did just recently reach Stage 3 proposal status, so it'll probably become official in ES2017 or ES2018. If you happen to be using the Create-React-App tool, that has the object spread Babel plugin already enabled.
var player = {score: 1, name: 'Jeff'};
var data=  {...player};

Flexy Menu - Responsive Horizontal & Vertical Menu | Basic Aria

Recently I have to add Aria to Flexy menu. I have attached the code.
//flexy.js
(function($){

	jQuery.fn.flexymenu = function(options){
		var settings = {
			 speed: 300,
			 type: "horizontal",
			 align: "left",
			 indicator: false,
			 hideClickOut: true,
			 submenuTrigger: "hover",
			 showDelay: 0,
			 hideDelay: 0,
			 mobileShowDelay: 0,
			 mobileHideDelay: 0,
			 scrollable: false,
			 scrollableMaxHeight: 400
		}
		$.extend( settings, options );
		
		var bigScreen = false;
		var menu = $(this);
		var lastScreenWidth = windowWidth();

Pages