Safely get a nested value inside an object

Today, I will share how could you safely get a nested value rather using hacks like this
const nestedVal = (
  obj &&
  obj.lorem &&
  obj.lorem.ipsum &&
You could use code like this
function get(obj, path) {
    const valueFromPath = path.split('.').reduce((previousValue, pathItem) => {
        if (typeof previousValue === 'undefined') return; // Will finish the rest of the iterations unfortunately :(

        const nextValue = previousValue[pathItem];

        return nextValue;
    }, obj);

    return valueFromPath;