Kindly wait a moment, post will be visible in just 5 seconds.
Rizwan Khan
Posted on 5 January 2022
I have written a utility funtion to get value from a object and if value is not present then it returns default value given by you.
eg:
what if any property of myObj not available then it will break your code and user cant see anything.
My Solution to objects
use getValue function to get either right value or user given default value
if c value available then it will return c value else it will return null
getValue(object, path_to_property, user_default_value)
Above Solution will work with all older and newer browsers
Another Simplest solution to the problem is modern es6 syntax
lets use same example
if i try to access something which is not present within the object
if i try to complicate things a little more
p is undefined and now i am trying to access a property of undefined got error boom
Modern Solution to the problem which will work with all modern browsers
India
Coding is an art and I love art
Learn trending tech & full-stack development. Book now
0 Comments