You can use this for shallow comparison:
// Returns true if the values are equal (shallow)
// for all properties that both objects have
function compareData(a,b){
return Object.keys(a).filter( k => k in b ).every( k => a[k] === b[k] );
}
It will return false for your objects because one has a number for age and the other has a string. It will return true for these objects:
var a = {name1:'alisha',age:18,subject:{main:'javascript',major:'maths'}};
var b = {name1:'alisha',age:18};
Example:
console.log( compareData( {}, {age: 5} ) ); // true (no shared properties)
console.log( compareData( {age: 5}, {age: 5} ) ); // true (equal shared properties)
console.log( compareData( {age: 4}, {age: 5} ) ); // false
var a = {name1:'alisha',age:18,subject:{main:'javascript',major:'maths'}};
var b = {name1:'alisha',age:18};
console.log( compareData( a, b ) ); // true
function compareData(a,b){
return Object.keys(a).filter( k => k in b ).every( k => a[k] === b[k] );
}