0% found this document useful (0 votes)
841 views13 pages

Learning Step by Step - 222

The document provides a comprehensive guide on setting up a TypeScript development environment, including installation steps and creating necessary files. It explains variable types in JavaScript, distinguishing between primitive and non-primitive data types, and covers modules, functions, and operators. Additionally, it includes examples of a simple calculator and a banking application using the Inquirer library for user input.

Uploaded by

mzjq4all
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
841 views13 pages

Learning Step by Step - 222

The document provides a comprehensive guide on setting up a TypeScript development environment, including installation steps and creating necessary files. It explains variable types in JavaScript, distinguishing between primitive and non-primitive data types, and covers modules, functions, and operators. Additionally, it includes examples of a simple calculator and a banking application using the Inquirer library for user input.

Uploaded by

mzjq4all
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Learning Step by Step:

Installation: Install node.js, VS code, TypeScript, Github, npm, Inquirer from


NPM, Prettier from NPM, Math from NPM

Create Environments: How to create file and folder for coding etc;
a. Create file and then open with code.
b. Create New Terminal on VS. Code and set it in Command Prompt.
c. Type, tsc –init to generate tsconfig.json file.
d. Type npm init -y to generate package.json file
e. Type npm i @types/node -D to install package-lock.json file and
node_modules.
f. Create .gitignore file and type node_modules in it.
g. Create app.ts file and type any code in it.
h. Type tsc app.js to compile transcript code (TS CODE) into Java Script (JS
CODE).
j. Type node app.js to execute code.
k. Create file from Github and run it to VS Code
l. Published file on NPM

3 Type of Variable:
(a). var, (b). let and (c). const)
a. Var: Declare and Re-assignable
b. Let: Declare and Re-assignable (changeable)
c. Const: Declare but Not Re-assignable (not-changeable)

Modules
In TypeScript, just as in ECMAScript 2015, any file containing a top-level import or
export is considered a module. Conversely, a file without any top-level import or export
declarations is treated as a script whose contents are available in the global scope (and
therefore to modules as well).
What is ECMAScript 2015?
ES6 or the ECMAScript 2015 is the 6th and major edition of the ECMAScript language
specification standard. It defines the standard for the implementation of JavaScript and
it has become much more popular than the previous edition ES5. ES6 comes with
significant changes to the JavaScript language.

Data: Data types in JavaScript define the data type that a variable can store.
JavaScript includes primitive and non-primitive data types. The primitive data types in
JavaScript include string, number, boolean, undefined, null, and symbol. The non-
primitive data type includes the object. Two type of Data:

a. Primitive Data: b. Non-Primitive Data:

 String  Array
 Number  Object
 Boolean  Function
 Undefined
 Null
 Symbol

One of the most popular programming languages nowadays is JavaScript. Every


modern web browser already has it preinstalled and it can be used to create front-end
and back-end apps using a variety of frameworks and libraries. Scripts are what this
language refers to as programs. They can be included directly in the HTML of a web
page and executed immediately when the page loads. Plain text is used to deliver and
run scripts. They don’t require any further setup or compilation to function. We will learn
about JavaScript’s various data types and different types of functions.

Primitive Data
String: The String object is used to represent and manipulate a sequence of
characters.

Number: In JavaScript, a number can be a primitive value (type of =


number) or an object (type of = object). The value of () method, is used internally
in JavaScript to convert Number objects to primitive values. There is no reason to
use it in your code. All JavaScript data types have a value of () and a to String ()
method.

Boolean: Very often, in programming, you will need a data type that can
only have one of two values, like
 YES / NO
 ON / OFF
 TRUE / FALSE

For this, JavaScript has a Boolean data type. It can only take the
values true or false.

Undefined: A variable that has not been assigned a value is of type


undefined . A method or statement also returns undefined if the variable that is
being evaluated does not have an assigned value. A function returns undefined if
a value was not returned .

Null: In JavaScript, null is a special value that represents an empty or


unknown value. For example, let number = null; The code above suggests that
the number variable is empty at the moment and may have a value later.

Symbol: Symbol Properties ; is Concat Spreadable, Indicates if an object


should be flattened to its array elements ; iterator, Returns the default iterator for
an object. The "=>" symbol is known as the "equals greater than" symbol or the
hash rocket.

Non-Primitive Data
Array: If you have a list of items (a list of car names, for example),
storing the cars in single variables could look like this:
let car1= "Saab";
let car2= "Volvo";
let car3 = "BMW";

However, what if you want to loop through the cars and find a specific
one? And what if you had not 3 cars, but 300?, However, what if you want
to loop through the cars and find a specific one? And what if you had not 3
cars, but 300?, The solution is an array!. An array can hold many values
under a single name, and you can access the values by referring to an
index number.

Objects: In JavaScript, almost "everything" is an object:


 Booleans can be objects (if defined with the new keyword)
 Numbers can be objects (if defined with the new keyword)
 Strings can be objects (if defined with the new keyword)
 Dates are always objects
 Maths are always objects
 Regular expressions are always objects
 Arrays are always objects
 Functions are always objects
 Objects are always objects

All JavaScript values, except primitives, are objects. For example;

In real life, a car is an object.

A car has properties like weight and color, and methods like start and
stop:

Object Properties Methods

car.name = Fiat car.start()

car.model = 500 car.drive()

car.weight = 850kg car.brake()

car.color = white car.stop()

All cars have the same properties, but the property values differ from
car to car.

All cars have the same methods, but the methods are performed at
different times.

Function: Definition of Function is a JavaScript, function is defined with the


function keyword, followed by a name, followed by parentheses (). Function
names can contain letters, digits, underscores, and dollar signs (same rules as
variables). The parentheses may include parameter names separated by
commas: (parameter1, parameter2, ...)

Operators: Operators are the symbols between values that allow different
operations like addition, subtraction, multiplication, and more. JavaScript has
dozens of operators, so let's focus on the ones you're likely to see most often.

1. Whit spaces: Extra space (Name sey pehly enter press)


2. ARRAY: Array is also called as a Set of various elements: Elements, diffrenet data types (String,
integer) representation of an ARRAY. [….]
3. For Straing uses : [ “…..”, “…..”, ….], i.e; [“Salman”, “Usman”, “Qaiser”]
4. For Integer/Float/Number : [……, ……, ……..] ie; [2, 7, 9].
let Names :string[] = ["Saleem", "Meraj", "Najm"];

let i=0; i<Names.length; i++


console.log(Names[i]);

b. Non-Primitive Data
Dated: 11 March 2024

Variables:

Variable is a container for data. 3 types of variables:

a. Let :
b. Cost
c. Var: is a key word for (reassign and re declare

Type script , java script key word search Assignment:

ISFAYAN

03059487339

DATA TYPE
Two type of Data:

a. Primitive Data
b. Non-Primitive Data

A. Primitive Data type b. Non- Primitive Data type


 String  Array
 Number  Object
 Boolean  Fuction
 Undefined
 Null
 Symbol

 String: To use “h”, double quote


 String: To use ‘h’, single quote
 String: To use `h`, backticks

Variable Naming:

Don’t Does
You can not use reserved names (words) Use camel case variable names
Can not begin with number eg; let myName = “Ali”
Can not use space in a name let myMarks = “95”
No other symbol other then ‘$’ or ‘_’ with number in name:
eg; let position10 = “Shahid”;
with symbol
eg; let position_10 = “Noman”
let total$ = 100

Let vs const vs var


Var : can be re-declared and update. It is global scope variable

Let: can not be re-declared and updated. It is block scope variable

Const: can neither be re-declared and nor updated. It is block scope variable.

Assignment – Simple Calculator


15 Mar 2024, Friday 4th Ramadhan

import inquirer from "inquirer";

const answer = await inquirer.prompt([


{ message: "Enter first number", type: "number", name: "firstNumber" },
{ message: "Enter second number", type: "number", name: "secondtNumber"
},
{ message: "Enter third number", type: "number", name: "thirdNumber" },
{
message: "select one of the operator to perform operation",
type: "list",
name: "operator",
choices: ["addition", "subtraction", "multiplication", "division"],
},
]);
console.log (answer);
1. import inquirer from "inquirer"; let myBalance = 40000; let pinCode =
7287; console.log (Your current balance is : ${myBalance}); console.log (PIN Code : $
{pinCode}); let ansPin = await inquirer.prompt([ { name: "pin", message:
"Enter your Pin Code:", type: "number" } ]); if (ansPin.pin === pinCode)
{ console.log ("Your PIN Code is Correct!"); let operationAns = await
inquirer.prompt([ { name : "operation", message : "What do you want to
do?!", type : "list", choices : ["Withdraw","Check Balance"] } ]); if
(operationAns.operation === "Withdraw") { let withdraw = await
inquirer.prompt([ { name : "amount", message : "Select the Amount:", type :
"list", choices :[10000, 20000, 30000, 40000,50000] } ]); if
(withdraw.amount > myBalance) {
console.log("insufficient amount!"); }else {let amountLeft = myBalance -
withdraw.amount;
console.log( The Remaining Balance Is : ${amountLeft}); } }else if
(operationAns.operation === "Check Balance") {
console.log( Your Current Balance Is : ${myBalance}); } }else { console.log("Pin
Code is inccorect\nPlease enter the correct pincode!") }
2. [2:03 AM]
Mein ne fast ke bajaye options rakh diye hai like 10000 20000 30000
and so on
import inquirer from "inquirer";
let myBalance = 20000; TITLE

let myPin = 820026;

let pinAnswer = await inquirer.prompt

({
1. name: "pin", PIN
2. message: "Enter your pin number?",
3. type: "number",

});
if (pinAnswer.pin === myPin)
console.log("Correct pin code!");

let operationAnswer = await inquirer.prompt

({
name: "operation",

message: "Please select option.", OPERATION

type: "list",

choices: ["withdraw", "check balance", "fast cash"],

});

if (operationAnswer.operation === "withdraw")

let amountAns = await inquirer.prompt

([

{name: "amount",
AMOUNT ANSWER
message: "Enter your amount?",

type: "number",

},
]);

myBalance -= amountAns.amount;

if (amountAns.amount <= myBalance) {

console.log(`Your remaining balance is: ${myBalance}`);


IF INSUFFICIENT BALANCE
} else {

console.log("Insufficient balance");

else if (operationAnswer.operation === "check balance") { CHECK BALANCE


console.log(`Your current balance is: ${ myBalance}`);

else if (operationAnswer.operation === "fast cash"){

console.log("Choose cash amount for withdraw."); FAST CASH


let cashAmountAns = await inquirer.prompt({

name:"cashAmount",

message:"Please select your cash amount option.",

type:"list",

choices:["1000", "5000", "10000", "15000"]

});

if (cashAmountAns.cashAmount === "1000"){ CURRENT BALANCE

console.log(`Your current balance is: ${myBalance -= 1000}`);

else if (cashAmountAns.cashAmount === "5000"){

console.log(`Your current balance is: ${myBalance -= 15000}`);

else if (cashAmountAns.cashAmount === "10000"){

console.log(`Your current balance is: ${myBalance -= 10000}`);

else if (cashAmountAns.cashAmount === "15000"){

console.log(`Your current balance is: ${myBalance -= 5000}`);

}
}

else {

console.log("Incorrect pin number.");

You might also like