Learning Java Script Basics-Part 1
I have started learning Javascript to work on Cypress/Webdriver IO for Automation of Angular applications. I will share the key points so that it may be useful for others to learn/revise.
So in part 1 lets start with some basics.
Note: For complete repo visit https://github.com/Jadalaajay16/Javascript.git and choose master branch.
console.log(“Hello World”)
//JavaScript accepts both double and single quotes:
let a=4
console.log(a) //op: 4
console.log(typeof(a)) //op:number
//JavaScript has only one type: numbers (not like other languages contains float,doublt,int etc..)
//Numbers can be written with, or without decimals:
let b = 234.6
console.log(typeof(b)) //op:number
var c = “Rahul Shetty”
console.log(typeof(c)) //op:string
let required = true
console.log(typeof(required)) //op:boolean
//null and undefined
// let c = a+b ( it do not work -we cannot redeclare variable with let keyword but possible with var)
c = a+b // reassigning is allowed with let
//var c=a+b (this is also allowed)
console.log(c) //op:238.6
console.log(!required) //op: false
//var:both redeclaring and reassigning works
//let: redeclaring not allowed, reassigning is allowed
//const: both redeclaring and reassigning does not work
//instanceof: Returns true if an object is an instance of an object type
//JavaScript has dynamic types. This means that the same variable can be used to hold different data types:
let x; // Now x is undefined
x = 5; // Now x is a Number
x = “John”; // Now x is a String
console.log(x) //op: John
JavaScript Objects: JavaScript objects are written with curly braces {}.
Object properties are written as name:value pairs, separated by commas.
const person = {firstName:”John”, lastName:”Doe”, age:50, eyeColor:”blue”};
let car; // Value is undefined, type is undefined
//Any variable can be emptied, by setting the value to undefined. The type will also be undefined.
car = undefined; // Value is undefined, type is undefined
//An empty value has nothing to do with undefined. An empty string has both a legal value and a type.
let car = “”; // The value is “”, the typeof is “string”
Please do comment if you find any improvements/corrections/clarifications to improvise this article.