Updated April 1, 2023
Definition of JavaScript values()
JavaScript values are the values that comprise values like Booleans, Strings, arrays, numbers, etc. Its behavior is the same as other programming languages as values are possessing some definite properties which is being used as per the requirement and run time environment while executing the JavaScript. The properties being defined by the Value further consist of the key which refers to a name followed by the value of the element or the property object. A simple representation or example dealing to make JavaScript Values understandable is a Record. The dot operator is further being used to access the Properties of the JavaScript Values.
Syntax:
The syntax under fixed values are written either with decimals or without decimals as follows:
Without decimals – any integer numbers
For example: 100
With decimals – with decimal numbers
For example: 100.5
The syntax for JavaScript Values under variable values are written either with decimals or without decimals as follows:
var a;
a=6;
Explanation: In the above example for representing the syntax can be put using decimal or non-decimal values. In case, of Variable values first a variable a is taken and then substituting values in the variable a.
How JavaScript values() Method Works?
- This method is basically divided into two types namely fixed JavaScript fixed values and JavaScript Variable Values method.
- JavaScript fixed value variable is also known as JavaScript Literals and Variable value is known as JavaScript variables.
- Working of JavaScript values method works in a way that these values consist of some properties which are further possessing some values in the key and value pair format, then the dot operator is used to call and access the value having the key to access the particular element in the property of the actual value.
- For writing any fixed values which means the JavaScript literals it is a prime important rule to write numbers with or without decimals and string in the form of text written within a single quote or a string written using double quote.
- In case of variable value JavaScript or variables it is written in way where first a variable is taken into consideration to store some values in it and then use the same declared variable used for storing the values in the declared variable. Followed by an equal sign which is used to assign value to the variable.
Let’s see how these two variables work in runtime environment and what are the basic requirement at what time?
- While defining the variable as fixed and dynamic it also has its association with the static and dynamic environment execution static type is mostly used at compile time and dynamic when running without a program which means at run time. So, we can relate the fact with fixed and dynamic variable.
- There is one more very interesting fact hidden behind the execution of JavaScript Values variables which is it makes some arbitrary distinction between the fixed and dynamic values variables which is somewhat of type that:
- It consists of some primitive types of values which include booleans, numbers, strings, null, and undefined.
- Remaining all values are objects.
- Next comes into picture the question then how can a clarity be presented between the arbitrary state of primitive values and object property values of itself and the clarity goes somewhat in this fashion that each object and its properties when compared to primitive type has its unique property and is quite equal to itself. On the other hand, all primitive values encode the same value which means it has no uniqueness for itself.
Example to illustrate how property of an object is accessed.
var c = {}; // creating an empty object
obj.x=567;//writing of property
obj.x//reading of property
'xyz'.toUpperCase() //for calling a method
Examples
Following are the example are given below:
Example #1
Program to represent the fixed value with decimal value representation.
Code:
<!DOCTYPE html>
<html>
<body>
<h2>For Fixed Value or literal representation of JavaScript Numbers</h2>
<p>Good to represent number that can be written with decimals.</p>
<p id="demo5"></p>
<script>
document.getElementById("demo5").innerHTML = 83.5;
</script>
</body>
</html>
Output:
Example #2
Program to represent the fixed value of the JavaScript Values without decimal number value representation.
Code:
<!DOCTYPE html>
<html>
<body>
<h2>For Fixed Value or literal representation of JavaScript Numbers</h2>
<p>Good to represent number that can be written without decimal.</p>
<p id="demo5"></p>
<script>
document.getElementById("demo5").innerHTML = 70;
</script>
</body>
</html>
Output:
Example #3
Program to represent the fixed value of the JavaScript Values with value in single quote representation.
Code:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Strings with literals </h2>
<p>Strings written with single quotes.</p>
<p id="demo3"></p>
<script>
document.getElementById("demo3").innerHTML = 'Anu Dutt';
</script>
</body>
</html>
Output:
Example #4
Program to represent the fixed value with value in double quote representation.
Code:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Strings with literals </h2>
<p>Strings written with double quotes.</p>
<p id="demo3"></p>
<script>
document.getElementById("demo3").innerHTML = "Anu Dutta1";
</script>
</body>
</html>
Output:
Example #5
Program to represent the dynamic or variable value with storing and assigning the value in variable p.
Code:
<!DOCTYPE html>
<html>
<body>
<h2>To represent the dynamic JavaScript Variables</h2>
<p> p is considered as a variable.
Then, p gets assigned with a value of 6:</p>
<p id="demo4"></p>
<script>
var p;
p = 9;
document.getElementById("demo9").innerHTML = p;
</script>
</body>
</html>
Output:
Example #6
Program to represent Values with storing and assigning the value in a variable and that too inside an object type and then accessed to represent those values in the form of object.
Code:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects for JavaScript Value within object reresentation</h2>
<p id="demo8"></p>
<script>
var scooter = {type:"versa", model:"latest", color:"red"};
document.getElementById("demo8").innerHTML = "The scooter is of type " + scooter.type;
</script>
</body>
</html>
Output:
Conclusion
JavaScript Values are of two types which is fixed type and variable type and hence is made used according to the run time and compile time environment at the time of execution but there are some non-primitive and primitive data types that have totally different format of representation with the values so defined.
Recommended Articles
This is a guide to JavaScript values(). Here we also discuss the definition and how javascript values() method works? along with different examples and its code implementation. You may also have a look at the following articles to learn more –