Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

TOPIC: JAVASCRIPT: 1.

Embed Inline JavaScript Code in HTML


2. Create an External JavaScript File
PROPERTY
HOW TO EMBED INLINE JS CODE?
JAVASCRIPT 1. Add Javascript in the <Head> Tags
2. Add Javascript in the <Body> Tags
- Web enhancing language, through
which we can change a stand-alone HOW TO CREATE EXTERNAL JS CODE?
page of content into an engaging, 1. Add a file with a file extension .js
interactive and intelligent experience
- it was developed by Netscape WHAT ARE THE OTHER POSSIBLE
Corporation and was initially known DISPLAY OPTION IN JS?
as “Live Script” . JavaScript was
also referred to as ECMA Script. 1. innerHTML
(European Computer - This method sets or returns the
Manufacturer’s Association) HTML content of an element. You
can also say that it is used to access
WHY USE JS? an element.
- Developers can implement the
following features:
● Display timely and relevant content
updates
● Display interactive maps 2. document.write()
● Insert drop-down and - This method is mostly used for
hamburger-style menus testing purpose. it is used to write
● Play audio and video some content or JavaScript code in
● Zoom in and out of images a Document. Also used to delete all
● Add 2D/3D graphics and animation the content from the HTML
● Display image galleries in a carousel document and inserts the new
format content.
● Insert hover effects
● Display and hide menus
● Alert users to invalid characters
when typing passwords
3. window.alert()
HTML, CSS, JAVASCRIPT - You can use alert box to display
- You first structure your content on data. The alert box is mostly used
the web page with HTML, then add when you want an information to
stylistic elements and a proper come through to the user. It is
layout with CSS. Next, you need to displayed with a message and an
add dynamic and interactive OK button.
functions with HTML.

HOW TO ADD JAVASCRIPT TO HTML


4. console.log() The two most important syntax rules for
- The console.log() method outputs a fixed values are:
message to the web console. The
message may be a single string, or it 1. Numbers are written with
may be any one or more JavaScript or without decimals.
objects.

2. Strings are text, written


within double or single
JAVASCRIPT KEYWORDS quotes.
- JavaScript statements often start
with a keyword to identify the
JavaScript action to be performed.

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.

A JAVASCRIPT NAME MUST BEGIN


WITH:
● A letter (A-Z or a-z)
● A dollar sign ($)
● Or an underscore(_) 2. Using var

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 names can contain


NOTE: Spaces and line breaks are not letters, digits, underscores, and
important. dollar signs (same rules as
variables).
OBJECTS PROPERTIES PARENTHESES
- The name:values pairs in JavaScript
objects are called properties: - The parentheses may include
parameter names separated by
commas:
ex : (parameter1, parameter2, ...)

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"

TOPIC: DOCUMENT OBJECT


HOW TO USE CALLBACK FUNCTION MODEL (DMO)
- Javascript has a special type of
function called a constructor DOCUMENT OBJECT MODEL(DMO)
function, which is used to create - The Document Object Model (DOM)
objects. is a programming interface for
- You define a constructor function HTML(HyperText Markup
using the keyword “function” Language) and XML(Extensible
followed by a name that starts with markup language) documents.
an uppercase letter (called using - It defines the logical structure of
the “new” keyword) documents and the way a document
is accessed and manipulated.
For example, the following code defines a
constructor function named WHY DOM IS REQUIRED?
"Person" that creates an object with a name
and age property: - HTML is used to structure the web
pages and Javascript is used to add
behavior to our web pages.
- When an HTML file is loaded into
the browser, the javascript can not
understand the HTML document
directly. So, a corresponding
document is created(DOM).

HOW TO USE DEFAULT PARAMETERS


- JavaScript functions also have a STRUCTURE OF DOM:
feature called default parameters. - The term structure model is
They allow you to set default values sometimes used to describe the
for parameters in case they are not tree-like representation of a
passed when the function is called. document.
- Each branch of the tree ends in a
node, and each node contains
objects. Event listeners can be programs and scripts to dynamically
added to nodes and triggered on an access and update the content, structure,
occurrence of a given event. and style of a document."

PROPERTIES OF DOM THE W3C DOM STANDARD IS


SEPERATED INTO 3 DIFFERENT PARTS:
1. CORE DOM - standard model for all
document types
2. XML DOM - standard model for XML
documents
3. HTML DOM - standard model for
HTML documents

WHAT IS THE HTML DOM?


The HTML DOM is a standard object
model and programming interface for
WITH THE OBJECT MODEL, JAVASCRIPT HTML. It defines:
GETS ALL THE POWER IT NEEDS TO ● The HTML elements as objects
CREATE DYNAMIC HTML: ● The properties of all HTML elements
● The methods to access all HTML
● can change alltheHTML elementsin elements
the page ● The events for all HTML elements
● can change alltheHTML attributesin
the page
● can change allthe CSS stylesin the
page
● can remove existingHTML elements
and attributes
● can add newHTML elements and
attributes SOURCE CODE (ACT)
● can reactto all existingHTML
eventsin the page
● can create newHTML eventsin the
page

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

You might also like