SlideShare a Scribd company logo
1 of 22
Chapter 1
Basics of JavaScript Programming
K. K. Wagh Polytechnic, Nashik-3
Prof.P.S.Chavan
CO605.1: Create interactive web pages using program flow
control structure.
Object Properties:
 Object Name:
• Object is entity. In JavaScript document, window, forms, fields,
buttons are some properly used objects.
• Each object is identified by ID or name.
• Array of objects or Array of collections can also be created.
 Property:
• It is the value associated with each object.
• Each object has its own set of properties.
 Method:
• It is a function or process associated with each object.
• Ex: for document object write is a method.
 Dot Syntax: Used to access properties and methods of object.
 Main Event: Event causes JavaScript to execute the code. In JavaScript
when user submits form, clicks button, writes something to text box the
corresponding event gets triggered and execution of appropriate code is
done through Event Handling.
Prof.P.S.Chavan
Values:
 Values:
It uses six types of values:
• Number: It is numeric value can be integer or float.
• String: It is a collection of characters. Enclosed within single or
double quote.
• Boolean: It contains true and false values. Values can be compared
with variables and can be used in assignment statement.
• Null: This value can be assigned by reserved word ‘null’. It means no
value. If we try to access null value error will occur.
• Object: It is the entity that represents some value. Ex: Form is an
object on which some components can be placed and used.
• Function: It is intended for execution of some task. There are
predefined and user defined functions. The ‘function’ keyword is used
to define function.
Prof.P.S.Chavan
Keywords:
• These are the reserved words having some special meaning associated
with it.
abstract else instanceof super
boolean enum int switch
break export interface synchronized
byte extends let this
case false long throw
catch final native throws
char finally new transient
class float null true
const for package try
continue function private typeof
debugger goto protected var
default if public void
delete implements return volatile
do import short while
double in static with
Prof.P.S.Chavan
Operators and Expressions:
Prof.P.S.Chavan
Sr.
No.
Type Operator Meaning Example
1. Arithmetic + Addition or Unary plus c=a+b
- Subtraction or Unary
minus
d=-a
* Multiplication c=a*b
/ Division c=a/b
% Mod c=a%b
2. Logical && AND Operator 0&&1
|| OR Operator 0 | | 1
3. Increment ++ Increment by one ++i or i++
4. Decrement -- Decrement by one --i or i--
5. Conditional ? : Conditional Operator a>b?true:false
Operators and Expressions cont.:
Prof.P.S.Chavan
Sr.
No.
Type Operator Meaning Example
6. Assignment = Is assigned to a=5
+= Add a value then assign a+=5 (a=a+5)
-= Subtract a value then assign a-=5(a=a-5)
*= Multiply a value then assign a*=5(a=a*5)
/= Divide a value then assign a/=5(a=a/5)
7. Relational < Less than a<4
> Greater than a>4
<= Less than equal to a<=4
>= Greater than equal to a>=4
== Equal to a==4
!= Not Equal to a!=4
=== equal value and equal type a===5
!== not equal value or not equal
type
a!==5
JavaScript Expressions
• Expressions
• Any unit of code that can be evaluated to a
value is an expression.
• Since expressions produce values, they can
appear anywhere in a program where
JavaScript expects a value such as the
arguments of a function invocation.
Prof.P.S.Chavan
1.Primary Expressions:
• Primary expressions refer to stand alone
expressions such as literal values, certain
keywords and variable values. Examples include
the following:
• 'hello world'; // A string literal
23; // A numeric literal
true; // Boolean value true
sum; // Value of variable sum
this; // A keyword that evaluates to the current
object
Prof.P.S.Chavan
2.Arithmetic Expressions:
• Arithmetic expressions evaluate to a numeric
value. Examples include the following
• 10; // Here 10 is an expression that is
evaluated to the numeric value 10 by the JS
interpreter.
• 10+13; // This is another expression that is
evaluated to produce the numeric value 23
Prof.P.S.Chavan
3.String Expressions:
• String expressions are expressions that
evaluate to a string. Examples include the
following
• 'hello';
'hello' + 'world'; // evaluates to the string
'hello world'
Prof.P.S.Chavan
4.Logical Expressions
• Expressions that evaluate to the boolean value
true or false are considered to be logical
expressions. This set of expressions often
involve the usage of logical operators &&
(AND), ||(OR) and !(NOT). Examples include
• 10 > 9; // evaluates to boolean value true
10 < 20; // evaluates to boolean value false
• true; //evaluates to boolean value true
• a===20 && b===30; // evaluates to true or
false based on the values of a and b
Prof.P.S.Chavan
5.Left-hand-side Expressions:
• Also known as lvalues, left-hand-side
expressions are those that can appear on the
left side of an assignment expression.
Examples of left-hand-side expressions include
the following:
• // variables such as i and total
i = 10;
total = 0;
Prof.P.S.Chavan
6.Assignment Expressions:
• When expressions use the = operator to assign
a value to a variable, it is called an assignment
expression. Examples include
• average = 55;
Prof.P.S.Chavan
7.Object and Array Initializers
• These initializer expressions are sometimes called
“object literals” and “array literals.” Unlike true
literals, however, they are not primary
expressions, because they include a number of
subexpressions that specify property and element
values.
• Array initializers have a slightly simpler syntax,
and we’ll begin with those.
• An array initializer is a comma-separated list of
expressions contained within square brackets.
• Prof.P.S.Chavan
Prof.P.S.Chavan
[] // An empty array: no expressions inside
brackets means no elements
[1+2,3+4] // A 2-element array. First element is 3,
second is 7
Function Definition Expressions
• In a sense, a function definition expression is a
“function literal” in the same way that an object
initializer is an “object literal.”
• A function definition expression typically consists
of the keyword function followed by a comma-
separated list of zero or more identifiers (the
parameter names) in parentheses and a block of
JavaScript code (the function body) in curly
braces. For example:
Prof.P.S.Chavan
Prof.P.S.Chavan
// This function returns the square of the
value passed to it.
var square = function(x)
{
return x * x;
};
8.Property Access Expressions
• A property access expression evaluates to the
value of an object property or an array
element. JavaScript defines two syntaxes for
property access:
• expression . identifier
• expression [ expression ]
Prof.P.S.Chavan
9.Invocation Expressions
• An invocation expression is JavaScript’s syntax
for calling (or executing) a function or method.
• f(0) // f is the function expression; 0 is
the argument expression.
• Math.max(x,y,z) // Math.max is the function;
x, y and z are the arguments.
• a.sort() // a.sort is the function; there are
no arguments.
Prof.P.S.Chavan
Prof.P.S.Chavan
Quiz
Prof.P.S.Chavan
Prof.P.S.Chavan

More Related Content

Similar to LO-2 Chapter-1.pptx

Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in javaShashwat Shriparv
 
Java Script
Java ScriptJava Script
Java ScriptSarvan15
 
Java Script
Java ScriptJava Script
Java ScriptSarvan15
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4thConnex
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfkatarichallenge
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & AnswersRatnala Charan kumar
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3BeeNear
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptxAtharvPotdar2
 
Brixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 RecapBrixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 RecapBasil Bibi
 
1669958779195.pdf
1669958779195.pdf1669958779195.pdf
1669958779195.pdfvenud11
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptFu Cheng
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developersJim Roepcke
 
7. Pointers and Virtual functions final -3.pptx
7. Pointers and Virtual functions final -3.pptx7. Pointers and Virtual functions final -3.pptx
7. Pointers and Virtual functions final -3.pptxAbhishekkumarsingh630054
 
XII Computer Science- Chapter 1-Function
XII  Computer Science- Chapter 1-FunctionXII  Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-FunctionPrem Joel
 

Similar to LO-2 Chapter-1.pptx (20)

Java script
Java scriptJava script
Java script
 
Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in java
 
Java Script
Java ScriptJava Script
Java Script
 
Java Script
Java ScriptJava Script
Java Script
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4th
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdf
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx
 
Brixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 RecapBrixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 Recap
 
1669958779195.pdf
1669958779195.pdf1669958779195.pdf
1669958779195.pdf
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developers
 
7. Pointers and Virtual functions final -3.pptx
7. Pointers and Virtual functions final -3.pptx7. Pointers and Virtual functions final -3.pptx
7. Pointers and Virtual functions final -3.pptx
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
About Python
About PythonAbout Python
About Python
 
Javascript analysis
Javascript analysisJavascript analysis
Javascript analysis
 
XII Computer Science- Chapter 1-Function
XII  Computer Science- Chapter 1-FunctionXII  Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-Function
 

Recently uploaded

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 

Recently uploaded (20)

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 

LO-2 Chapter-1.pptx

  • 1. Chapter 1 Basics of JavaScript Programming K. K. Wagh Polytechnic, Nashik-3 Prof.P.S.Chavan CO605.1: Create interactive web pages using program flow control structure.
  • 2. Object Properties:  Object Name: • Object is entity. In JavaScript document, window, forms, fields, buttons are some properly used objects. • Each object is identified by ID or name. • Array of objects or Array of collections can also be created.  Property: • It is the value associated with each object. • Each object has its own set of properties.  Method: • It is a function or process associated with each object. • Ex: for document object write is a method.  Dot Syntax: Used to access properties and methods of object.  Main Event: Event causes JavaScript to execute the code. In JavaScript when user submits form, clicks button, writes something to text box the corresponding event gets triggered and execution of appropriate code is done through Event Handling. Prof.P.S.Chavan
  • 3. Values:  Values: It uses six types of values: • Number: It is numeric value can be integer or float. • String: It is a collection of characters. Enclosed within single or double quote. • Boolean: It contains true and false values. Values can be compared with variables and can be used in assignment statement. • Null: This value can be assigned by reserved word ‘null’. It means no value. If we try to access null value error will occur. • Object: It is the entity that represents some value. Ex: Form is an object on which some components can be placed and used. • Function: It is intended for execution of some task. There are predefined and user defined functions. The ‘function’ keyword is used to define function. Prof.P.S.Chavan
  • 4. Keywords: • These are the reserved words having some special meaning associated with it. abstract else instanceof super boolean enum int switch break export interface synchronized byte extends let this case false long throw catch final native throws char finally new transient class float null true const for package try continue function private typeof debugger goto protected var default if public void delete implements return volatile do import short while double in static with Prof.P.S.Chavan
  • 5. Operators and Expressions: Prof.P.S.Chavan Sr. No. Type Operator Meaning Example 1. Arithmetic + Addition or Unary plus c=a+b - Subtraction or Unary minus d=-a * Multiplication c=a*b / Division c=a/b % Mod c=a%b 2. Logical && AND Operator 0&&1 || OR Operator 0 | | 1 3. Increment ++ Increment by one ++i or i++ 4. Decrement -- Decrement by one --i or i-- 5. Conditional ? : Conditional Operator a>b?true:false
  • 6. Operators and Expressions cont.: Prof.P.S.Chavan Sr. No. Type Operator Meaning Example 6. Assignment = Is assigned to a=5 += Add a value then assign a+=5 (a=a+5) -= Subtract a value then assign a-=5(a=a-5) *= Multiply a value then assign a*=5(a=a*5) /= Divide a value then assign a/=5(a=a/5) 7. Relational < Less than a<4 > Greater than a>4 <= Less than equal to a<=4 >= Greater than equal to a>=4 == Equal to a==4 != Not Equal to a!=4 === equal value and equal type a===5 !== not equal value or not equal type a!==5
  • 7. JavaScript Expressions • Expressions • Any unit of code that can be evaluated to a value is an expression. • Since expressions produce values, they can appear anywhere in a program where JavaScript expects a value such as the arguments of a function invocation. Prof.P.S.Chavan
  • 8. 1.Primary Expressions: • Primary expressions refer to stand alone expressions such as literal values, certain keywords and variable values. Examples include the following: • 'hello world'; // A string literal 23; // A numeric literal true; // Boolean value true sum; // Value of variable sum this; // A keyword that evaluates to the current object Prof.P.S.Chavan
  • 9. 2.Arithmetic Expressions: • Arithmetic expressions evaluate to a numeric value. Examples include the following • 10; // Here 10 is an expression that is evaluated to the numeric value 10 by the JS interpreter. • 10+13; // This is another expression that is evaluated to produce the numeric value 23 Prof.P.S.Chavan
  • 10. 3.String Expressions: • String expressions are expressions that evaluate to a string. Examples include the following • 'hello'; 'hello' + 'world'; // evaluates to the string 'hello world' Prof.P.S.Chavan
  • 11. 4.Logical Expressions • Expressions that evaluate to the boolean value true or false are considered to be logical expressions. This set of expressions often involve the usage of logical operators && (AND), ||(OR) and !(NOT). Examples include • 10 > 9; // evaluates to boolean value true 10 < 20; // evaluates to boolean value false • true; //evaluates to boolean value true • a===20 && b===30; // evaluates to true or false based on the values of a and b Prof.P.S.Chavan
  • 12. 5.Left-hand-side Expressions: • Also known as lvalues, left-hand-side expressions are those that can appear on the left side of an assignment expression. Examples of left-hand-side expressions include the following: • // variables such as i and total i = 10; total = 0; Prof.P.S.Chavan
  • 13. 6.Assignment Expressions: • When expressions use the = operator to assign a value to a variable, it is called an assignment expression. Examples include • average = 55; Prof.P.S.Chavan
  • 14. 7.Object and Array Initializers • These initializer expressions are sometimes called “object literals” and “array literals.” Unlike true literals, however, they are not primary expressions, because they include a number of subexpressions that specify property and element values. • Array initializers have a slightly simpler syntax, and we’ll begin with those. • An array initializer is a comma-separated list of expressions contained within square brackets. • Prof.P.S.Chavan
  • 15. Prof.P.S.Chavan [] // An empty array: no expressions inside brackets means no elements [1+2,3+4] // A 2-element array. First element is 3, second is 7
  • 16. Function Definition Expressions • In a sense, a function definition expression is a “function literal” in the same way that an object initializer is an “object literal.” • A function definition expression typically consists of the keyword function followed by a comma- separated list of zero or more identifiers (the parameter names) in parentheses and a block of JavaScript code (the function body) in curly braces. For example: Prof.P.S.Chavan
  • 17. Prof.P.S.Chavan // This function returns the square of the value passed to it. var square = function(x) { return x * x; };
  • 18. 8.Property Access Expressions • A property access expression evaluates to the value of an object property or an array element. JavaScript defines two syntaxes for property access: • expression . identifier • expression [ expression ] Prof.P.S.Chavan
  • 19. 9.Invocation Expressions • An invocation expression is JavaScript’s syntax for calling (or executing) a function or method. • f(0) // f is the function expression; 0 is the argument expression. • Math.max(x,y,z) // Math.max is the function; x, y and z are the arguments. • a.sort() // a.sort is the function; there are no arguments. Prof.P.S.Chavan