Affiliate link

JavaScript - Variables

Defining variables

Variables can be scoped by global or block-scoped (class, function, or namespace).

  • Global variables
  • Block-scoped variables

Define variable using var, let, const or nothing

JavaScript, often abbreviated as JS, is a programming language which all web developers need to learn for developing website. JavaScript is used along with HTML/CSS.

<script type="text/javascript">
    var a = '123';
    function updateA() {
        a = '234'; // Global scope
    }
    updateA();
    console.log(a);
    function updateText() {
        var a = '234'; // Function scope
    }
    updateText();
    console.log(a);
</script>
Affiliate link
Affiliate link
Advertisment
Fiverr
Ad - SiteGround WooCommerce hosting - best home for your online store. Fast WooCommerce, Free SSL, Top support. Learn more.
rocket.net