Day-2 of JavaScript
Printing a statement in js
console.log('hello world');
Variables in js
The let keyword is for variables which holds values and can be changed.
let message = "hello";
console.log(message) // output is hello
message = "world";
console.log(message); // output is world
The const keyword is for variables which hold values and can not be changed.
const message = "hello";
message = "world";
console.log(message);
output will be:
message = "world";
^
TypeError: Assignment to constant variable.
Datatypes in js
// primitive datatypes
let str1='havi';
let str2="rishi";
let str3=`geetha`;
let n=12;
let n1=1.2;
let big=12345678901234n;
let lovescoding=false;
n2=null // can declare a null value
// reference datatypes
const n3=Symbol();
let class_section = {
name: 'tenth class',
section: 'C'
};
JavaScript is dynamically typed language or not?
Yes, because in Javascript we can reassign the same variable with different type.
let name1 = "haveela";
console.log(typeof name1); // output is string
name1 = 99;
console.log(typeof name1); // output is number
name1 = false;
console.log(typeof name1); // output is boolean