01. Intro to programming, variables and data types
01. Intro to programming, variables and data types
Intro to programming,
variables and data types
Outline
● Introduction to Programming
● Introduction to Algorithm
● Introduction to JavaScript
● Variable
● Data Types
● Introduction to TypeScript
● Type Conversion
● Operator
Introduction to Programming
● What is programming ?
● Why learn programming ?
● What is programming language ?
What is Programming ?
Programming is the process of creating a set of instructions that tell computer to
perform a task.
What is Programming Language ?
A programming language is a vocabulary and set of grammatical rules for instructing a
computer or computing device to perform specific tasks.
Example :
Problem-solving skills are the ability to identify problems, brainstorm and analyze
answers, and implement the best solutions. Programmers with good problem-solving
skills is both a self-starter and a collaborative teammate; they are proactive in
understanding the root of a problem and work with others to consider a wide range of
solutions before deciding how to move forward.
Think Like a Programmer
–Steve Jobs–
Introduction to Algorithm
● What Is an Algorithm?
○ An algorithm is a set of step-by-step procedures, or a set of rules to follow, for
completing a specific task or solving a particular problem. Algorithms are all
around us.
● Why are Algorithms Important to Understand?
○ Algorithmic thinking, or the ability to define clear steps to solve a problem,
is crucial in many different fields. Even if we’re not conscious of it, we use
algorithms and algorithmic thinking all the time. Algorithmic thinking allows you
to break down problems and conceptualize solutions in terms of discrete steps.
Being able to understand and implement an algorithm requires you to practice
structured thinking and reasoning abilities.
Introduction to Algorithm
● Where are Algorithms Used as a Web Developer?
Algorithms are used in every part of IT industries. They form the field's backbone.
Algorithm gives the computer a specific set of instructions, which allows the
computer to do everything. Algorithms written in programming languages
that the computer can understand.
Computer algorithms play a big role in how social media works: which posts show
up, which ads are seen, and so on. These decisions are all made by algorithms.
JavaScript can execute not only in the browser, but also on the server, or actually on
any device that has a special program called the JavaScript engine.
What is JavaScript ?
Javascript is single-threaded, non-blocking, asynchronous, concurrent language.
Single Statement
; is Semicolon
Variable
Variable is a “named storage” for data. We can use variable to store any data you
need.
Example
In package delivery apps, there’s information about package details, address, sender’s
name, etc.
Create (declare)
variable
String “Hello”
String Used to represent textual data Object Is an entity having properties and methods
(keyed collection) → Will be explained in the next
Number & Used to hold decimal values as well as values session
BigInt without decimals
Array Used to store more than one element under a
Boolean Represents a logical entity and can have two single variable → Will be explained in the next
values: true and false session
The main feature that TypeScript adds is static typing, which allows developers to specify
the types of data that variables and functions can hold. This can help to catch errors early in
the development process and make code more maintainable.
Why use TypeScript?
There are several benefits to using TypeScript, including:
● Improved type safety: TypeScript static type checking can help to catch errors early
in the development process, which can save time and frustration.
● Better code readability: TypeScript type annotations can make code more readable
and easier to understand.
● Increased developer productivity: TypeScript can help developers to be more
productive by catching errors early and making code more maintainable.
Getting started with TypeScript
To get started with TypeScript, you can follow these steps:
When storing a value type in memory, it adds an element to the top of the stack with the
value of the newly created variable. When creating a new variable and assigned the first one
to the new one, it adds a new element on top of the stack with the value of the new
variable.
{
name: ‘Jhonny’,
1 “Jhonny” age: 26
}
{
name: ‘Jhonny’,
1 “Jhonny” age: 26
}
2 “Jhonny”
{
name: ‘Jhonny’,
1 “Jhonny” age: 26
}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
eference/Global_Objects/String
Template Literals
● Template literals (template strings) allow you to
use strings or embedded expressions in the form
of a string.
● Template literals are enclosed by backtick (`)
characters instead of double or single quotes.
● With template literals, you can get :
○ A multiline string → a string that can span
multiple lines.
○ String formatting → the ability to substitute
part of the string for the values of variables
or expressions. This feature is also called
string interpolation.
○ HTML escaping → the ability to transform a
string so that it’s safe to include in HTML.
Number Built-in Method
Number built-in method Global built-in method & property
● toString ● Number
● toExponential ● parseInt
● toFixed ● parseFloat
● toPrecision
● valueOf
● MAX_VALUE
● MIN_VALUE
● POSITIVE_INFINITY
● NEGATIVE_INFINITY
● NaN
Type Conversion
● String Conversion
○ String(123) // return a string from a number
literal 123
● Numeric Conversion
○ const num = "3" * "3" // return 9 in number
○ Number("3.14") // return 3.14 in number
● Boolean Conversion
○ Boolean(1) // return true
○ Boolean(0) // return false
○ Boolean("Hello") // return true
○ Boolean("") // return false
Date Data Type
It stores the date, time and provides methods for date/time management.
Date Built-in Method
Get Methods Set Methods
● getFullYear ● setDate
● getMonth ● setFullYear
● getDate ● setHours
● getHours ● setMilliseconds
● getMinutes ● setMinutes
● getSeconds ● setMonth
● getMilliseconds ● setSeconds
● getTime ● setTime
● getDay
● Date.now
● Date.parse
Basic Operators
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder (modulo)
** Exponentiation
Unary, Binary and Operand
● An operand is what operators are applied to. For instance, in the multiplication of 5 * 2
there are two operands: the left operand is 5 and the right operand is 2. Sometimes,
people call these “arguments” instead of “operands”.
Note : Only work with binary “+”. Other arithmetic operators work only with numbers and always convert their operands to
numbers.
Modify in Place
We often need to apply an operator to a variable and store the new result in that same
variable.
Increment & Decrement
● Increasing or decreasing a number by one is among the most common numerical
operations.
● Increment ++ increases a variable by 1.
● Decrement -- decreases a variable by 1
Postfix & Prefix Form
● The operators ++ and -- can be placed either before or after a variable.
● When the operator goes after the variable, it is in “postfix form”: counter++.
● The “prefix form” is when the operator goes before the variable: ++counter.
● If we’d like to increase a value and immediately use the result of the operator, we need
the prefix form
● If we’d like to increment a value but use its previous value, we need the postfix form
Comparison Operators
Comparison operators
are used in logical
statements to
determine equality or
difference between
variables or values.
Given that x = 5,
this table would
explains the
comparison operators
Introduction to Pseudocode
Before we start our exercise on the next
slides, let’s talk about Pseudocode first.