Initializer in javascript, is a value assigned during declaration of a variable, using Automatic, var, let and const keyword. It is the initial value by which a variable is initialized.
Syntax
var|let|const variable_name = initializer;
Initializer with Automatic variables
Automatic variables must be initialized with initial value, without providing initial value it throws error. So, Initializer is mandatory with automatic variables.
<script>
a; // Error
b; // Error
</script>
In above example variable a and b have not assigned any initial value. So, it gives error.
The right way is to assign initial value to automatic variables, as given in below example.
<script>
a = 40;
b = 50;
</script>
Initializer with var variables
Initializer is optional with var variables.
<script>
var a = 40;
a = 50;
</script>
Here variable a is declared and initialized with value 40. So, the value 40 is initializer. And in next line variable a is again assigned a new value 50, so it not an initializer, it is assigned value.
Initializer with let variables
Initializer is optional with let variables in javascript.
<script>
let b = 40;
</script>
variable b is initialized with value 40 during declaration, Here, value 40 is initializer.
Initializer with const variables
Initializer is mandatory with const variables. In below example variable PI is initialized with 3.14 value. So, value 3.14 is initializer. without initialization, it gives error.
<script>
const PI = 3.14;
</script>