0% found this document useful (0 votes)
19 views

CSS Chapter 1 Part 1

css

Uploaded by

arpitajagdale1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

CSS Chapter 1 Part 1

css

Uploaded by

arpitajagdale1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

UNIT I

Basics of JavaScript
CHAPTER 1 Programming
Syllabus
1.1 Features of JavaScript
1.2 Object Name, Property, method, Dot syntax, main event.
1.3 Values and Variables
1.4 Operators and Expressions- Primary Expressions, Object and
Array initializers, function definition expression, property access
expressions, invocation expressions.
1.5 IfStatement, if... else,if..elseif, nested if statement.
1.6 Switch ..case statement
1.7 Loop statement - for loop, for...in loop, while loop, do..while loop,
continue statement.
1.8 Querying and setting properties and deleting properties, property
getters and setters.

Introduction toJavaScript
GQ. Whatis JavaScript?
GQ Enlist different uses of JavaScript.
GQ.State the need ofJava Script.
GQ How to write JavaScript program?
GQ. Howto print data in JayaScript?
C
JavaScript is a dynamic computer programming language that executes
On the browser. It modifies static HTML web pages into interactive web
Pages by dynamically updating content, validating form data, controlling
multimedia, animate images on the web pages.
Scripting Language (MSBTE)
ClientItSide
is a scripting language for creating dynamic web page content.
improvingsite visitors' interaction with
for
creates elements menus, animated graphics, and dynamic web page,
such as dropdown
colors. background,
Itis lightweight and most commonly used as a part of web pages, whoe
implementations allow client-side script to interact with the user and

make dynamic pages.


programming language with
It is an interpreted
capabilities.
web pages alive"
object-oriented
JavaScript was initially created to "make
The programin this language is called scripts. They can be written with
HTML in a web pages and run automatically as the page loads.
Scripts are provided and executed as plain text. They don't need srat
preparation or compilation to run.
JavaScript can execute not only in the browser, but alsoon the server. or
actually on any device that has a special program called the JavaScrin
engine.
The browser has an embedded engine sometimes called a "JavaScript
virtual machine" and the different engines have different codenames like
V8 in Chrome, Opera and Edge, and SpiderMonkey in Firefox.
JavaScript is commonly used for client-side scripting on the World Wide
Web, and it is increasingly being used for writing server applications and
services using Node.js.
History
JavaScript was invented by Brendan Eich in 1995, and became an
ECMA standard in 1997.
JavaScript became a fully with its own
specification called ECMAScript.independent language
ECMAScript is the official name of the language and it isaa JavaScrp!
Standard meant to ensure the
different web browsers. interoperability of web Po
ESÍ
ECMAScript
and ES6. Sinceversions have been YearES2,
ES3,
2016 new abbreviated
versions are namedto byES1, (ECMASCri!
2016 /2017 / 2018).
(NewSyll. w.e.f academic year à Tech-Neo Pubicatio
19-20) (D5-16A)
Client Side Scripting Language (MSBTE) (Basics of JavaScript Prog.) Pg. no. (1-3)

Use

JavaScript can put dynamic text into an HTML page.


JavaScript can react to events.
C JavaScript can read and write HTML elements.
JavaScript can be used to validate data.
JavaScriptcan be used to detect the visitor's browser.
JavaScript can be used to create cookies
S Why Study JavaScript?
JavaScript is one of the three languages allweb developers must learn:
1. HTML to define the content or structure of web pages.
2. CSS to specify the layout of web pages. It described the look and
formatting of a document.
3. JavaScript to program defines dynamic behavior of web pages;
provides programming logic for interaction with the user and handle
user events.

Editor

There are different editors for writing the JavaScript program:


1. Notepad 2. Visual Studio Code
3. Eclipse 4. Atom
5. Sublime Text 6. Brackets
7. NetBeans 8. Vim

How to write JavaScript program?


JavaScript can be inserted within the head, the body, or use external
JavaScript file
The HTML <Script>...<Jscript> tag is used to insert a JavaScript into an
HTML page
Syntax
<seript language ="javascript" type="text/javascript"src="external
JavaSeript file path">

(New Syll. w.e.f academic year 19-20) (D5-16A) alTech-Neo Publications


(MSBTE)
(Basics of JavaScript Prog.) Pg.
Client Side Scripting Language no.(l-4)
/Javascript code goes here
</script>
OR
<script>
IHJavascript code goes here
</script>
The language and type attributes not required in new JavaScript versions.
It isoptional.
Ending statements with a semicolon is Optional; required when we want
to put multiple statements on a single line.
There are three different ways JavaScript can be used in HTML, such as:
1. Inline JavaScript
Inline JavaScript, the JavaScript code can be add in HTML tags in some
special JavaScript-based attributes.
For example, HTML tags have event attributes that allow to
execute
some code inline when an event is triggered.
Example
<html>
<head><title><iieKhead
<body>
<button onclick="alert(Hello,
</body>
World!">Cick mne! </button>
<ihtml>
2. Internal JavaScript
Second way JavaScript can be use
HTML document. internally with the <script> tag inthe
Example
<html>
<head>

<title>...</itle>
<s(Newcript>document.write(Hello, World!');</seript>
Syll. w.ef
academic year 19-20) (D5-16A) ITech-Neo Publications
Client Side Scripting Language (MSBTE)
(Basics of JavaScript Prog.) Pg. no.
</head>
(1-5)
<body>... S/body>
</html>
4. External JavaScript
Third way JavaScript can be adding
the src attribute. externally using <script> tag with
The src attribute specify the path of
external JavaScript file.
Example (External File)
JavaScript
Pile:messagejs
function msg
alert(Hello, World!y

HTML Fle. index.htm


<hm
<head
<title External JavaScript Rile< /title
<scnpttype textavascript srcmessage.jscript
<head
<body>
<pWelcome to JavaScriptsS/p
<lorm
<input type"button value click onelick msg
<orm>
</body>
Shtml>
How to print data in JavaScript?
There are three different
ways:
1. Using document.wrlte)
The
document.write() is used to print the content to the HTML document.
(New Syll. W.e.f academic year 19-20) (D5-16A) Tech-Neo Publications
Client Side Scripting Language (MSBTE) (Basics of JavaScript Prog.) Pg.
no.(1-6)
Example
document.write(Hello, World!');
2. Using alert()

The alert() method displays an alert box over the current window with
the
specified message.
Example
alert("Hello, World!");
3. Using console.log()

The console.log() is used in debugging the code and print the data in browser
console.

Example
console.log(HelloWorld');
1.1 FEATURES OF JAVASCRIPT

UQ. List any four features of Javascript. MSBTE - Q. 1(a), W-19, 2 Marks
GQ. State any four features of JavaScript.
JavaScript is an object-based scripting language.
Giving the user more control over the browser.
It Handling dates and time.
It Detecting the user's browser and OS,
It is light weighted.
Client - Side Technology
JavaScript is a scripting language and it is not java.
JavaScript is interpreter based scripting language.
JavaScriptis case sensitive.
JavaScript is object based language as it provides predefined objects.
Every statement in JavaScript must be terminated with semicolon (;
Syntax of
Most of the JavaScript control statements Syntax is same as
control statements in C 1anguage.

Tech-Neo Publication
(New Syll. w.e.f academic year 19-20) (D5-16A)
Cient Side Scripting Language (MSBTE) (Basics of JavaScript Prog.) Pg. no. (1-7)
An important part of Javascript is the ability to create new functions
withinscripts. Declare a function in JavaScript using function keyword.
N1.2 OBJECT NAME, PROPERTY, METHOD, DOT
SYNTAX, MAIN EVENT

Go. Describe the different ways of creating the object using JavaScript.
GO, Explain the term object with property in JavaScript with exarmple.
GO. Explain the term object with method/function in JavaScript with
example.
GQ Explain howto accessing object propertiesin JavaScript.
GQ. Howto add methodto a JavaScript Object ?
GQ. State the use of this keyword in JavaScript
GO. Explain the terms main event in lavaScript with example.

a 1.2.1 Object
AJavaScript object is a collection of named values.
JavaScript objects are containers for named values, called properties and
methods.
There are different ways to create new objects:
1. Create a single object, using an object literal.
2. Creating instance of Object directly, with the keyword new
3. Define an object constructor, and then create objects of the
constructed type.
4. Create an object using Object.create()
1. JavaScript Object by object literal
An object literal is a list of name:value pairs inside curly braces {}.
Using an object literal,define and create an object in one statement.
Syntax
object= Dertyl:valuel, property2:value2... propertyN:valueN}
OR
object= {keyl:valuel, key2:value2 ... keyN:valueN}
(New Syll. w.e.f academic year 19-20)(D5-16A) Gech
Tech-Neo Publications
(Basics of JavaScript
Prog.)
ClientSide
Scripting
Language
(MSBTE)
Pg.no (4
Example </head>
</title >
<html> Example
<title>Object
<head>
<body> "text/javaScript"> "Somwanshi", age:25}:
<scripttype = {fname:"Ravi",Iname:
=
const person {
person)
document.write(person[x] + "<br/>")
for (letx in

</script>
</body
</html>
Output
Ravi
Somwanshi
25 Object
instance of
2. By creating new Object() and then ad:
object using
Create a new JavaScript
properties.
Syntax
var objectName new Obect}S

Example
<htmi>
<head><itle> Object Example</itle> </head
<body>
<seript type text/javaScript
const person new Object0;
person.fname-"Rayi!,
person.Iname="Somwanshi
person.age=25; person.age
document. write(person.fname +""4 Person.Jname + "is " +
years old.");
</script>
</body>
</html>
Tech-NeoPublca
(NewSyll. w.e.f academic year 19-20) (D5-16A)
Client Side Scripting Language (MSBTE)
(Basics of JavaScript Prog.) Pg. no.
(1-9)
Output
Ravi Somwanshi is 25 years old.
2 By using an Object constructor
We need to create function with
be assign in the current object by arguments
using this
and each argument value can
The this keyword refers to the current
keyword.
object.
Example
<html>
<head><title> Object Example</itle></head
<body>
<seript type="textjavaScript">
function emp(id, name, salary){
thisad=id;
this.name=name;
this.salary =salary;
e=new emp(103,"Prashant Somwanshi",30000);
document.write(e.id +" "+e.name +""+e.salary);
</seript>
</body>
<{html>
Output
103 Prashant Somwanshi 30000
4. Usingthe Object.create() method
Objects can also be created using the Object.create() method.
t allows choosing the prototype object for the object we want to create,
without having to define a constructor function.
Example
<html>
<head> <itle> Object Exanple</útle> </head>
<body>
<script type =
Const person "text/javaScript">
(New Syl.. w.e.f academic yyear 19-20) (D5-16A) Tech-Neo Publications
(Basics of JavaScript Prog.) Pg.rno.
Language (MSBTE)
ClientSide
Scripting (1-10)
properties
fname:"Ravi",
Default value of
Iname:"Somwanshi",

age:25,
function as a value
/ using
print:function()

document.write(this.fname "<br/>");

object called objl


/ Create new person type
const objl =0bject.create(person);
objl.print(); / Output: Ravi.

/Create new person type object caled obj2


const obj2 =Object.create(person)
obj2.fname ="Prashant',
obj2.print): / Output: Prashant
</script>
<{body>
</htmi>
Output
Ravi
Prashant
a 1.2.2 Property
InJavaScript, "key: value" pairs are called
properties.
Properties the values associated with a JavaScript objecl.
are
AJavaScript object is a
collection of unordered properties.
Example
let person =

fname:"Ravi".
Iname:"Somwanshi",
(New Syll. w.e.f
academic year 19-20) (D5-16A) Tech.NeoPublico
Client Side Scripting Language (MSBTE) (Basicsof JavaScript Prog.) Pg. no. (1-11)
age: 25

};
Here, fname: "Ravi", Iname : "Somwanshi" and age: 25 are properties.
A 1.2.3 Method
Methods are actions that can be performed on objects.
An object method is an object property containing a function definition.
Methods are functions stored as object properties.
Example
Const person =

fnarme : "Ravi',
Iname : "Somwanshi".
age : 25.
Wusing function as a value
print: function)
{
console.log(hello);

}
l accessing method
person.print(); // hello
NOte: In above example, function is use as a value for the print key. So, we
heed to use person.print() instead of person.print to call the function inside
the object.
Adding aMethod to a JavaScript Object
We can also add a method in an object.

Example
creating an empty object
let student = ;
lladding a
student.nameproperty ;
=Ravi'
adding amethod

(New Syll. w.e.f academic year 19-20) (D5-16A) al Tech-Neo Publications


Client Side Scripting Language (MSBTE)
(Basics of JavaScript Prog.) Pg.
student.print function)
no.(1-12
{
console.log('hello');

/ accessing a method
student.print(); // hello
"this" Keyword
To access a property of an object from within a method of the same object
we need to use this keyword.

Example
const person

name: Ravi',
age: 25,
l accessing nane property by using this.name
print: function()

console.logt The name is + t this. name);

person.print);
Output
This name is Raví
properu
In the above example, a person object is created. It contains
(name and age) and a method print.
object,this
In the method print, while accessing a property of an
keyword is used.

1.2.4 Dot Syntax


Accessing Object Propertles
We can access the value of a property by using its key.

LaTech-NeoPublicati"
(NewSyll. w.e.f academic year 19-20) (D5-16A)
Client Side Scripting Language (MSBTE) (Basics of JavaScript Prog.) Pg. no. (1-13)
1. Using dot Notation
We can access the value of aproperty by using (.) dot notation.
Syntax
objectName.key
Example
let person =

fname : "Ravi
Iname : "Somwanshi",
age : 25

l accessing property
console.log(person.fname): // Ravi
2. Using bracket Notation

We can access the value of a property by using [ ]bracket notation.


Syntax
objectNamef'propertyName"]
OR

objectNamef"expression"|
Example
let person

fname :"Ravi",
Iname :"Somwanshi",
age : 25

X= person.age}
accessing property by propertyName

aTech-Neo Publications
(New Syll. w.e.f academic year 19-20) (D5-16A)
(Basics of JavaScript
Client Side Scripting Language (MSBTE) Prog.) Pg.
console.log(person["Sname"); / Ravi ,no.(1 4
/accessing property by expression
console.log(person[x); / 25
1.2.5 Main Event
The change in the state of an object is known as an Event.
In html, there are various events which represents that Some
performed by the user or by the browser. activity is
When JavaScript code is included in HTML,. JavaScript reacts Over
these
events and allows the execution. This process of reacting over the even.
is called Event Handling. Thus, JavaScript handles the HTML evente .:
Event Handlers.

The following HTML events and their event handlers are:


Mouse events
The mouse events that are invoke by mouse.

Event Performed Event Handler Description


click Onclick When mouse click on an element
mouseover onmouseover When the cursor of the mouse
comes over the element
mouseout
Onmouseout When the cursor of the mouse
leaves an element
mousedown pressed
Onmousedown When the mouse button is
over the element
released
mouseup
Onmouseup When the mouse button is
Over the element
mousemove takes
Onmousemove When the mouse movement

place.

(New Syll. w.e.f academic year B Tech-NeoPublica


19-20) (D5-16A)
Client Side Scripting Language (MSBTE) (Basics of JavaScript Prog.) Pg. no. (1-15)

Keyboard events
The keyboard events that are invoke by keyboard.
Event Performed Event Handlert Description
Keydown & Keyup Onkeydown &onkeyup When the user press
and then release the key

IS Formevents
The form events that are invoke by form.

Event Event Description


Performed Handler
focus onfocus When the user focuses on an element

submit onsubmit When the user submits the form

blur onblur When the focus is away from a form


element

change onchange When the user modifies or changes the


value of a form element

IS Window/ Document events


The windowevents that are invoke by window.

Event Event Description


Performed Handler

load onload When the browser finishes the loading of


the page
unload onunload When the visitor leaves the current
webpage, the browser unloads it
resize Onresize When the visitor resizes the window of
the browser

(New Syll. w.e.f academic year 19-20) (D5-16A) Tech-Neo Publications


(MSBTE)
(Basics of JavaScript Prog.) Pg.
Client Side Scripting Language no. (l-18
(onclick)
Mouse Event Example
<html>
<head><title>JavaScript Events </title></head>
<body>
<script language="Javascript" type="text/Javascript'">
function clickevent)

document.write("This is a JavaScript");
}
</script>
<form>
<input type="button" onclick="lickevent)" value="Click Me"
</form>
</body>
<{html

Output
(Before Click)

Javascript Events
File D:/TechNeo%20Publicationsievent.htmi

Cick Me

(After Click)
event.htnl

O FileD:/TechNeo%20Publications/event.htmi
This is a JavaScript

(New Syll. w.e.f academic year Tech-NeoPublicatlo"


19-20) (D5-16A)
Client Side Scripting Language (MSBTE) (Basics of JavaScript Prog.) Pg. no. (1-17)
1.3 VALUES AND VARIABLES

GO. How to declare and initialize the variable in JavaScript


GQ. List the ways to declare JavaScript variable.
GO, List different rules of variable names.
GQ. Explain different data types in JavaScript with example.
GQ. State the dynamictyping in JavaScript with example.
In a programming language, variables are used to store data values.
Variables are containers for storing values.
All JavaScript variables must be identified with unique names. "These
unique names are called identifiers.
Variable names follow these rules:
1. Names can contain letters, digits, underscores,and dollar signs.

2. Names must begin with a letter


3. Names can also begin with $ and
4. Names are case sensitive (y and Y are different variables)
5. Reserved words (like JavaScript keywords) cannot use as names.
6. By convention, variable names use camelcase like message,
yourAge, and myName.
There are three ways to declare JavaScript variable :
1. Using var 2 Using let
3. Using const
Always declare JavaScript variables with var, let, or const.
The var keyword is used in all JavaScript code from 1995 to 2015.
The let and const keywords were added to JavaScript in 2015.
If we want to run code in older browser, we must use var keyword.

I Declaring a variable
To declare a variable, we use the let, var and const keyword followed by
the variable name.
Undefined is also a primitive value in JavaScript. Undefined means
unknown value.

(NewSyll. w.e.facademic year 19-20) (D5-16A) Tech-Neo Publications


(Basics of.JavaScript Prog.) Pg.
Client Side Scripting
Language (MSBTE
when no value
no.(118
undefined value is
Avariable or
an object has an
assigne
before using it.

Syntax
let <variable-name>;

Example
variable declaration andUndefined
let myName; /
let myAge;
S Initializing a variable
value.
declared, we need to initialize it with a
Once variable is
variable.
equal sign is used to assign value to
An
Syntax
value>
let <variable-name>

Example
let myName "Ravi", variable declaration and initialization
myAge = 25; l variable initialization
Constants

To declare a constant (unchanging) variable, use const keyword instead


of let or var.
Variables declared using const are called "constants. They cannot be
reassigned. An attempt to do SO Would cause an error.

Example
const myBirthday =18.04.1995
S Variable types / Data types
1, Numbers
We can store numbers in variables, either whole numbers like 30(alsocalled
floating
integers) or decimal numbers like 2.456 (also called floats or
point numbers).

(New Syll. w.e.f academic year 19-20) Tech-Neo Publicatio


(D5-16A)
Client Side Scripting Language (MSBTE) (Basics of JavaScript Prog.) Pg. no. (1-19)

Example
let myAge = 17;
2. Strings
Strings are pieces of text. When we give a variable a string value, we need to
wrap it in single or double quote marks.
Example
let myNarme "Ravi";
3. Booleans

Booleans can have two values, true or false.


Example
let flag = true;
4. Arrays

An array is a single object that contains multiple values enclosed in square


brackets and separated by commas.
Example
let myNameArray [Ravi, Akash, Lalitl:
5. Objects
A JavaScript object is a collection of named values.
JavaScript objects are containers for named values, called properties and
methods.
An object literal is a list of key:value pairs inside curly
braces {}.
Example
const person = fname:"Ravi, Iname:"Somwanshi, age:25};
Dynamictyping
JavaScript is a "dynamically typed language", which means that, unlike
Other languages, we don't need to specify what data some
type a variable will
Contain (numbers, strings, arrays, etC).

(New Syll. w.e.f


(Basics of JavaScript
Client Side Scripting Language (MSBTE) Prog.) Pg.
Example
no.(1-20)
let nyAge= 17; / Number Type
let myAge= "17"; / Sring Type
1.4 OPERATORS AND EXPRESSTONS - PRIMARY
EXPRESSIONS, OBJECT AND ARRAY
INITIALIZERS, FUNCTION DEFINITION
EXPRESSION, PROPERTY ACCESS
EXPRESSIONS, INVOCATION EXPRESSIONS
GQ. List the different operators in JavaScript.
GQ. Explain the tern operatorsinJavaScript with example.
GQ, List the different expressions in JavaScript.
IGQ. Explain the term expressions in JavaScript with example.
IGQ. List the arithmetic operators in Java Script.
GQ. List the bitwise operators in JavaScript.
GQ. List the logical operators in JavaScript.
GQ. List the assignment operators in JavaScript.
GQ. List the special operatorsin JavaSctipt.
List the comparison operators in Java script.
(MSBTE- Q. 1(b), W-19, 2 Marks)
S Operators
The operators are symbols that are used to perform
operations on operands
(i.e. variables or values).
Example
var süm=10+20:
Here, + is the arithmetic operator and= is the
10, 20 are called operands. assignment operator and su
There are following types of operators in
1 JavaScript.
Arithmetic Operators
2. Comparison (Relational) Operators
3
Bitwise Operators
4. Logical Operators
5. Assignment Operators
6. Special Operators

(NewSyll. w.e.f academic year 19-20) Tech-NeoPublicatio"


(D5-16A)
Client Side Scripting Language (MSBTE) (Basics of JavaScript Prog.) Pg. no. (1-21)

1. Arithmetic Operators
The arithmetic operators are used to perform arithmetic operations on the
operands.
Operator Description Example
Addition 10+20= 30
Subtraction 20-10 = 10

Multiplication 10*20 = 200


Division 20/10 = 2
% Modulus (Remainder) 20%10 = 0
++ Increment var a=10; a++; Now a = 11
Decrement var a=10; a--; Nowa =9
2. Comparison (Relational) Operators
The comparison operators are used compares the two operands. It is also
called as relational operators.
Operator Description Example
Is equal to 10==20 = false
Identical (equal and of same type) 10==20 = false
Not equal to 10!=20= true
!== Not Identical 20!==20 = false
Greater than 20>10= true
Greater than or equal to 20>=10 = true
< Less than 20<10 = false

Less than or equal to 20<=10 = false

3. Bitwise Operators
The bitwise operators perform bitwise operations on operands.
Operator Description Example
Bitwise AND (10==20 & 20==33) = false
| Bitwise OR (10==20120==33) =false

(New Syll. w.e.f academic year 19-20) (D5-16A) Tech-Neo Publications


(MSBTE) (Basics of JavaScript
Client Side Scripting Language Prog)
Po.no.
Operator Description
Bitwise XOR
Example
(10==20 A20==33)={

Bitwise NOT (~10) =-10

<<
Bitwise Left Shift (10<<2)= 40
Bitwise Right Shift (10>>2) =2
>>> Bitwise Right Shift with Zero (10>>>2) = 2

4. Logical Operators

The logical operators perform logical operations on operands.


Operator Description Example
&& Logical AND (10==20 && 20==33) = false
Logical OR (10==20 | 20==33) = false
Logical Not !(10==20) = true
5. Assignment Operators
The assignment operators are used to assign values or result to the operands

Operator Description Example


Assign 10+10 = 20
+=
Add and assign var a=10; a+=20; Now a =30
Subtract and assign var a=20; a-=10; Now a= 10
Multiply and assign var a=10; a*=20: Now a = 200
Divide and assign var a=10; a/=2: Now a =5
Modulus and assign var a=10; a%=2: Now a =0

(New Syll. w.e.f


academic year 19-20) (D5-16A) Tech-Neo Public
Client Side Scripting Language (MSBTE) (Basics of JavaScript Prog.)Pg. no. (1-23)

6. Special Operators
The following are the special operators in JavaScript:
Operator Description
(?:) Conditional Operator returns value based on the condition.
It is like if-else.

Comma Operator allows multiple expressions to be


evaluated as single statement.
delete Delete Operator deletes a property from the object.
in In Operator checks if object has the given property
Instance of checks if the object is an instance of given type
new creates an instance (object)
type of checks the type of object.
void it discards the expression's return value.

yield checks what is returned in a generator by the generator's


iterator.
Expressions
An expression is any valid unit of code that JavaScript interpreter can parse
and compute to produce a value.
a 1.4.1 Primary Expressions
Primary expressions are the simplestexpressions.
There are three groups of primary expressions: literal values, variable
references, and keywords.
1. Literal values
Literal values are constant values.
Example
"text" Ila string literal
125 l a number literal

(New Syll. w.e.f academic year 19-20)


(D5-16A) Tech-Neo Publications
Client Side Scripting Language (MSBTE) of JavaScript Prog.) Pg. no.
(Basics
.(1-24)
2.
Varlable references
Any identifier that appears in the code JavaScript interpreter assumes it is a
variable and tries to read its value.
Example
I/evaluates to the value of the variablex
price I/evaluates to the value of the variable price
undefined / a global variable undefined evaluates to the value undefined
3. Basic keywordss and reserved words thls keyword

The this' evaluates to the current objiect. It is use in a method to refer to the
current object
Example
this.name
this.displayName)
a 1.4.2 Object and Array Initializers
1, Object initializer expression
Object initializer creates object with literal notation and the value of this
expression is newly created object.
It uses curly brackets surrounding object properties separated by
Commnas.

Example
var obj =

propl: "value]".
prop2: 2
}:
2. Array nitlallzer expresslon
Array initializer creates array with literal notation and the
value of this
expression is newlycreated array.

(New Syll. w.e.f academic year 19-20) (D5-16A)


a Tech-Neo Publications
It consists of square brackets surrounding elements separated by
commas.

Example
var arr = [1,2, 3);

n 1.4.3 Function Definition Expression


Function expression defines a JavaScript function and the value of this
expression is newly defined function.
Example
var sum= function (x, y)
{
return x + y;

var z = sum (3, 4); |/7

A 1.4.4 Property Access Expressions


There are two ways to accesS a property of an object: either using the
object followed by a period () and an identifier or using the object (or
the array) followed by square brackets with an identifier inside.
It evaluates respectively to the value of an object property or an array
element.

Syntax
object.property lireference a property (or method) of an object
object{property]
object[property]
Example
var obj = (x: 1, y: 2}:
obj.x /
objl'y] 2
var arr = 2,3;
arr[l] II 3

(New Syll. w.e.f academic year 19-20) (D5-16A) Tech-Neo Publications

You might also like