Welcome Guest! (App Version 3.1)

websitnero logo name

Variables And Constants

Variables

These are data holding boxes and can hold any type of data -- strings, numbers, boolean, null, undefined or symbol. JavaScript variables are containers that keep values of any data-type. Their values can be changed over the time of the program run.

Example

<button onclick="alpha()"> Click </button>

<script>
var a = 10;
function alpha(){
  alert("Value of a is: " + a);
  a = 20; 
  alert("New Value of a is : " + a);
}
</script>
</html>

Constants

These are data holding packets like variables, but the value they contain does not change over time and always remains fixed. Constants are similar to variables. Only difference is that there value does not change over the course of program execution. Once set, its value will remain same throughout the program.

Example

<button onclick="alpha()"> Click </button>
<!-- See console, you'll get an error as constant 
cannot be assigned new value. -->

<script>
const a = 10;
function alpha(){
  alert("Value of a is: " + a);
  a = 20; 
  alert("New Value of a is : " + a);
}
</script>
WebsiteNero is highly optimized for learning various website developing technlogies. We try our best to add maximum modules and examples to help learn the concepts clearly and vividly. We try to present all content and examples as simple as we can removing any complexity to hurdle easy understanding. We try best provide you with worthful content, but we cannot guarantee full correctness of all the content on this site. While using this website, you agree to have read and accepted all our terms of use and conditions, cookie, and privacy policy. Copyright, 2013-2018 by websitenero.com. All Rights Reserved.