Professional Documents
Culture Documents
Cpet12 Midterm
Cpet12 Midterm
VARIABLES
- In a programming language,
variables are used to store data
values.
- JavaScript uses the keywords var,
let and const to declare variables.
- An equal sign is used to assign
values to variables.
STATEMENT
- JavaScript statements are
composed of: Values, Operators,
Expressions, Keywords, and OPERATORS
Comments - JavaScript uses arithmetic
operators ( + - * / ) to compute
values
EXPRESSIONS
- An expression is a combination of
values, variables, and operators
that computes to a value.
- The computation is called an
evaluation.
SYNTAX
- The JavaScript syntax defines two
types of values:
a. Fixed values are called Literals.
b. Variable values are called IDENTIFIERS
Variables. - Identifiers are JavaScript names.
- Identifiers are used to name VARIABLE
variables, keywords, and - Javascript variables can be declared
functions. in four ways:
- The rules for legal names are the
same in most programming 1. Automatically
languages.
CASE SENSITIVE
- All JavaScript identifiers are case
sensitive.
- The variables lastName and
lastname, are two different variables:
3. Using let
CAMEL CASE
- Historically, programmers have used
different ways of joining multiple
words into one variable name:
4. Using const
● Hyphens:
first-name, last-name, master-card,
inter-city.
● Underscore:
first_name, last_name, master_card,
inter_city.
● Upper Camel Case (Pascal Case):
FirstName, LastName, MasterCard, WHEN TO USE VAR, LET, OR CONST?
InterCity.
● Lower Camel Case: 1. Always declare variables
JavaScript programmers tend to use camel 2. Always use const if the value should not
case that starts with a lowercase letter: be changed
firstName, lastName, masterCard, interCity. 3. Always use const if the type should not
be changed (Arrays and Objects)
CHARACTER SET 4. Only use let if you can't use const
- JavaScript uses the Unicode 5. Only use var if you MUST support old
character set. browsers.
- Unicode covers (almost) all the
characters, punctuations, and
symbols in the world.
TOPIC: JS: OBJECT & OBJECTS METHOD
- Objects can also have methods
FUNCTION
- Methods are actions that can be
performed on objects
OBJECTS
- Methods are stored in properties as
- Objects are one of JavaScript's
function definitions
datatypes.
- Objects are variables too.
- Objects can obtain many values
- Object are used to store
key/value(name/value) collections
The values are written as
name: value pairs
(name and value separated by a colon) JAVASCRIPT FUNCTION
- A JavaScript function is a block of
OBJECTS DEFINITION code designed to perform a
- You define (and create) a JavaScript particular task.
object with an object literal: - A JavaScript function is executed
- The following example creates a when "something "invokes it (calls
JavaScript object with four key/value it).
properties: - A JavaScript function is defined with
the function keyword, followed by a
name, followed by parentheses ().
FUNCTION NAMES
FUNCTION RETURN
- When JavaScript reaches a return
statement, the function will stop
- You can access object properties in executing.
two ways: - If the function was invoked from a
a. objectName.propertyName statement, JavaScript will "Return "
b. objectName["propertyName"]
to execute the code after the This is helpful in situations where you want
invoking statement. to provide a default value
for a parameter in case it is not passed.
FUNCTION Here is an example:
- Functions often compute a return
value. The return value is "returned"
back to the "caller"
DOM
- The DOM is a W3C (World Wide
Web Consortium) standard.
- The DOM defines a standard for
accessing documents:
"The W3C Document Object Model (DOM)
is a platform and language-neutral
interface that allows