Skip to content

Commit

Permalink
Change var to const (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayparm authored May 21, 2022
1 parent b532fa3 commit f6df0fc
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tutorials/learn-js.org/en/Variables and Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Like almost every dynamic language, JavaScript is a "duck-typed" language, and t

We can define several types of variables to use in our code:

var myNumber = 3; // a number
var myString = "Hello, World!" // a string
var myBoolean = true; // a boolean
const myNumber = 3; // a number
const myString = "Hello, World!" // a string
const myBoolean = true; // a boolean

A few notes about variable types in JavaScript:

Expand All @@ -16,19 +16,19 @@ A few notes about variable types in JavaScript:

There are two more advanced types in JavaScript. An array, and an object. We will get to them in more advanced tutorials.

var myArray = []; // an array
var myObject = {}; // an object
const myArray = []; // an array
const myObject = {}; // an object

On top of that, there are two special types called `undefined` and `null`.

When a variable is used without first defining a value for it, it is equal to undefined. For example:

var newVariable;
const newVariable;
console.log(newVariable); //prints undefined

However, the `null` value is a different type of value, and is used when a variable should be marked as empty. `undefined` can be used for this purpose, but it should not be used.

var emptyVariable = null;
const emptyVariable = null;
console.log(emptyVariable);


Expand Down Expand Up @@ -59,9 +59,9 @@ myBoolean is equal to false

Solution
--------
var myNumber=4;
var myString="Variables are great.";
var myBoolean=false;
const myNumber=4;
const myString="Variables are great.";
const myBoolean=false;
console.log("myNumber is equal to " + myNumber);
console.log("myString is equal to " + myString);
console.log("myBoolean is equal to " + myBoolean);

0 comments on commit f6df0fc

Please sign in to comment.