var name = 'John Doe';
In this example, we declared a variable called
name and assigned it the value
'John Doe'. You can also declare multiple variables at once, like this:
var name = 'John Doe', age = 30;
var keyword has been replaced by
let keyword is used to declare variables that can be reassigned, while the
const keyword is used to declare variables that cannot be reassigned. Here is an example of using
const to declare variables:
let name = 'John Doe';
name = 'Jane Doe'; // valid
const age = 30;
age = 31; // error
In this example, we declared a variable
name using the
let keyword and assigned it the value
'John Doe'. We then reassigned the
name variable to
'Jane Doe', which is valid. On the other hand, we declared a variable
age using the
const keyword and assigned it the value
30. Attempting to reassign the
age variable results in an error, as the value of a
const variable cannot be changed.
String: Used to represent a sequence of characters, such as a word or a sentence. Strings are declared using single or double quotes, like this:
const age = 30;.
Boolean: Used to represent the values
const isMarried = false;.
Null: Used to represent a deliberate non-value.
Nullis often used to represent an unknown or undefined value. Here is an example of declaring a
const car = null;.
That’s it for today.
Thank you for reading. Happy Coding..!! 🙂