This article presents an outline of Pointers in JavaScript. In JavaScript, most of the things are Objects whether we analyze arrays, functions, etc, hence it is held as an Object-Oriented Programming Language. The only elements that are not objects are primitive data types. Primitive data types are permanent, and objects are changeable elements.
What are the Pointers in Programming?
Pointers are just variables that save the address of an object. They are passed by value. So you can change the object being pointed to, but you can not force the object to point to something else by moving it to a function.
<h2>Pointer in JavaScript</h2> <script> var pointer1 = {num: 787}; function pointer(obj){ obj.num--; } pointer(pointer1); alert(pointer1.num) </script>
References in JavaScript:)
- A vital thing to see is that pointers are generally used to perform call-by-reference.
- But we remember that JavaScript doesn’t support passing parameters by reference.
- How to perform the call-by-reference innovation in JavaScript?
- The answer to this problem is to create a variable inside an object or object literal.
Example of Pointers in JavaScript:)
<h2>Refernces in JavaScript</h2> <p id="refer"></p> <script> var ref = {outdoor:"CAR", indoor:"JEEP"}; document.getElementById("refer").innerHTML = ref; </script>
Conclusion
In conclusion, JavaScript primitive data types are constantly passed by value, whereas the values inner objects are moved by reference. It is essential to understand references in JavaScript which can help developers to evade common mistakes and write better execution scripts.