First program in javaScript (lt.30)
We will run the JavaScript programs in node.js which a run time environment for JavaScript , please try to avoid the window console as it can hamper the result and your ability to learn js in long run.
so install node.js and code with me :
just like printing any data to screen we use different syntax such as printf in c , cout in c++,
in JavaScript we use : console.log( value to be printed)
Variable : It is a type of container which is used to store value in ram for a particular time limit , so that it can be accessed easily .
Data types in Js:
- Primitive data types: they are core foundational data types.
number : 3 , 5.7 ; string: "aa" , 'hii' ; Boolean : true , false ; Null: means nothing not zero ; Undefined: ; Symbol : used to create unique identifiers for object properties ; BigInt: large numbers.
- Non primitive types:
array , objects
Keywords to be used in js:
let :Variables declared with let are block-scoped, meaning they are limited in scope to the block in which they are defined
const : Variables declared with const are also block-scoped. They cannot be reassigned once they are assigned a value.
var : we don't use var as it has many problems including the scope problem
Try to prefer const more in long run.
Program to demonstrate with it-
console.log("hello")
// console.log(this)
//if we print 'this' in console then it will give someoutput but in case of actual code editor ans is null
// undefined
let a
const sym = Symbol("this is symbol")
console.log('symbol : ', sym)
// Array
let names =["himanshu" , 'hii', 7 , false]
console.log(names)
// object
// object is an important concept in js
const person = {
name: 'captain',
age: 30,
occupation: 'Engineer'
};
console.log(person.age)
// let
let x = 120;
console.log(x);
// var
var t = 10;
console.log(t);
// const
const z = 20;
console.log(z);
// // a simple program
let price = 200;
console.log("price = ", price);
let gst = 0.18;
console.log("gst = ", gst);
console.log("coursePrice = ", gst * price + price);
console.log("coursePrice = ", gst * price - price);