Skip to content

03 Basics

SunilOS edited this page Aug 3, 2019 · 3 revisions

Define a variable and display at console

let name = "Ram"; console.log(name);

Define data types

  1. let first:number = 123; // number
  2. let second: number = 0x37CF; // hexadecimal
  3. let third:number=0o377 ; // octal
  4. let fourth: number = 0b111001;// binary
  5. let uname:string = "Hello Ram"; //String
  6. let lname:string = "How are You?"; //String

Define constant

  • const VAR = 10;
  • console.log("Value is: " +VAR);

Arrays and Tuples

Arrays

  • let arr:number[]; //
  • arr = [1, 2, 3, 4];
  • console.log(arr[0]);
  • console.log(arr[1]);

Tuples

  • let arrTuple = [1, "Ram", 2, "Shyam"];
  • console.log(arrTuple.length);
  • console.log(arrTuple);
  • console.log(arrTuple[0]);
  • console.log(arrTuple[1]);
  • console.log(arrTuple.pop()); // Remove an element
  • arrTuple.push("Python"); // Add an element
  • console.log(arrTuple.length);

Clone this wiki locally