Intro To Programming, Variables and Data Types
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
● Type Conversion
● Operator
Introduction to Programming
● What is programming ?
● Why learn programming ?
● What is programming language ?
What is Programming ?
Example :
Before we jump in to the Algorithm, let’s talk about problem solving first.
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
● 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
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.
Google’s programmers use algorithms to optimize searches, predict what users are going
to type, and more. In problem-solving, a big part of computer programming is knowing
how to formulate an algorithm.
Introduction to JavaScript
● What is JavaScript ?
● Why use JavaScript ?
● Setting up development environment
● Let’s write our first code !
● JavaScript code structure
What is JavaScript ?
● Easy to Learn
● Popularity
● Large Community
● Speed
● Versatility
● Interoperability
Setting Up the Development Environment
Single Statement
Semicolon
Variable
String “Hello”
● Must contain only letters, digits, or the symbols “$” and “_”
● The first character must not digit
● Case-sensitive
● Can’t use reserved words
Data Types
String Used to represent textual data Object Is an entity having properties and methods (keyed
collection) → Will be explained in the next session
Number & BigInt Used to hold decimal values as well as values
without decimals Array Used to store more than one element under a single
variable → Will be explained in the next session
Boolean Represents a logical entity and can have two values:
true and false
● Mutable is a type of variable that can be changed. (contains of: non primitive) it is also called as reference type
● Immutable are the objects whose state cannot be changed once the objects is created. (contains of: primitive)
immutable it is also called as value type.
● Declaring variable with const doesn’t make the value immutable. It depends on data type.
Mutable vs Immutable
data.
Immutable
2 “Jhonny”
{
name: ‘Jhonny’,
1 “Jhonny” age: 26
}
Mutable
the result!
variable value?
2 “Jhonny”
{
name: ‘Jhonny’,
1 “Jhonny” age: 26
}
3 PersonPointer
2 “Jhonny”
{
name: ‘Jhonny’,
1 “Jhonny” age: 26
}
● slice ● padStart
● substring ● padEnd
● substr ● chartAt
● replace ● charCodeAt
● toUpperCase ● split
● toLowerCase ● indexOf
● concat ● lastIndexOf
● trim ● search
Template Literals
● 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
● 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”.
● An operator is unary if it has a single operand. For example,
the unary negation - reverses the sign of a number.
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
Operator Description
== Equal
!= Not equal
Since you already know about pseudocode, let’s solve this exercise through pseudocode first, and
then convert it into a programming code!