Skip to main content

Command Palette

Search for a command to run...

Javascript Accessors in action πŸš€

Updated
β€’1 min read
Javascript Accessors in action πŸš€

While discussing with my friends I came across one interesting question which excites me to create this blog entry.

The question was, how the following conditions get satisfied to print the text in the console.

How I solved it? πŸ’‘

Let's solve this with the help of Javascript Object.

First, we will define an object and use one of the Object Accessors.

Basically, there are two types of accessors in javascript

  • getters

  • setters

Here we are using get also we can say getters.

More about the accessors can be referred from here, https://www.w3schools.com/js/js_object_accessors.asp

Now we can see here that the output is printing that log as we expected.

It satisfies the first condition with the temp's actual value for the very first time because get accessor is not called until the value of the temp is actually used. This is because JavaScript uses a process called lazy evaluation.

Please let me know if you have any other approach to solve this.

Happy coding 😊

江

Hello, I want to find a partner to make a video player software, please contact me at jj5372035gmail.c o m

江

Hello, I want to find a partner to make a video player software, please contact me at jj5372035gmail.c o m

More from this blog

U

Utkal Labs's Engineering blog

20 posts

Team of experienced industry experts sharing a common goal to provide optimum solutions to any problem. Let's discuss: (+1)32390 05072, (+91)93383 08255