JavaScript introduction to variables

JavaScript is a dynamically typed programming language variables are declared using the following format
var `variablename` `value`
instead of
int integer = 100

In JavaScript a variable can accommodate any typeof value ie a variable can be assigned numbers, strings, functions, and objects.

among modern browsers or in "strict mode" variables can be declared in an alternative way using const and let keywords.

variable's defined this way's values can not be changed once they have been assigned. ie they are referred to as immutable.

var name = "John"
var lastname
var year = 2020
// var age
var male = true

console.log(typeof name) // string
console.log(typeof lastname) ///undefined
console.log(typeof age) // undefined
console.log(typeof year) // number
console.log(typeof male) // boolean

const pi  = 22 / 7
pi = undefined; // sometimes this can raise a typescript error
// assignment to constant variable in strict mode

console.log(pi) // 3.142857142857143

Comments

Popular posts from this blog

What is 'this.' keyword in JavaScript

How to iterate array elements using 'for loop' in JavaScript