SlideShare a Scribd company logo
Addison-Wesley’s
                              JavaScript Reference Card
           Kathleen M. Goelz and Carol J. Schwartz, Rutgers University

Javascript: A scripting language designed to be integrated       VARIABLES
into HTML code to produce enhanced, dynamic, interac-
                                                                 Definition: A placeholder for storing data. In JavaScript, a
tive web pages.
                                                                 declaration statement consists of the reserved word var and
                                                                 the name (identifier) of one or more variables.
DATA TYPES
                                                                 Format:
Definition: The classification of values based on the specific     var variable_name
categories in which they are stored.                               [var command is used to declare (create) variables]
Primitive Types: String, Boolean, Integer, Floating Point,       Examples:
Null, Void
                                                                   var myHouseColor
Composite Types: Object, Array, Function. Composite data
                                                                   var myAddress
types are in separate sections of the code.
                                                                   var vacation_house, condominium,
                                                                        primaryResidence
NUMERIC
                                                                 Rules for Naming Variables:
Integer: Positive or negative numbers with no fractional
                                                                   1. Variables cannot be reserved words.
parts or decimal places.
                                                                   2. Variables must begin with a letter or underscore and
Floating Point: Positive or negative numbers that contain a
                                                                      cannot begin with symbols, numbers, or arithmetic
decimal point or exponential notations.
                                                                      notations.
String: A sequence of readable characters or text, surround-
                                                                   3. Spaces cannot be included in a variable name.
ed by single or double quotes.
                                                                 Hints:
Boolean: The logical values True/False, etc. used to com-
                                                                   1. Although variables in JavaScript can be used without
pare data or make decisions.
                                                                      being declared, it is good programming practice to
Null: The variable does not have a value; nothing to report.
                                                                      declare (initialize), all variables.
Null is not the same as zero, which is a numeric value.
                                                                   2. Variable names are case sensitive; for example X does
Casting: Moving the contents of a variable of one type to a
                                                                      not equal x.
variable of a different type. You don’t move the contents to
a different variable; it stays in the same variable but the
data type is changed or “re-cast”.




                                                                                   ,!7IA3C1-dcahfj!:t;K;k;K;k
                                                                                      ISBN 0-321-32075-1
IF-ELSE Statement: A conditional branching statement
INITIALIZING VARIABLES
                                                                      that includes a path to follow if the condition is TRUE and
Use the declaration statement to assign a value to the vari-
                                                                      a path to follow if the condition is FALSE.
able. The value is on the right of the equal sign; the variable
                                                                      Format:
is on the left.
                                                                        if     (condition)   {
Format:
                                                                             statements if condition is TRUE;
  var      variable_name = value
                                                                        }
Examples:                                                               else    {
  var myHouseColor = “yellow”                                              statements if condition is FALSE;
  [literal string value yellow assigned to variable                     }
           myHouseColor]                                              Example:
  var myAddress = 473                                                   if    (score >= 65) {
  [numeric value 473 assigned to variable myAddress]                         grade = “Pass”;
  var    bookTitle = “Time Capsule”, cost =                                  message = “Congratulations”;
         28.95, publisher = “Tucker Bay”                                }
  [multiple variables can be assigned in one statement]                 else     {
                                                                           grade = “Fail”
                                                                           message = “Try again”;
DECISION MAKING AND                                                     }
CONTROL STRUCTURES
                                                                      IF-ELSE IF Statement: A conditional branching statement
Definition: Statements and structures used to change the              that allows for more than two possible paths. The first time
order in which computer operations will occur.                        a true condition is encountered, the statement is executed
Types:                                                                and the remaining conditions will not be tested.
Conditional Branching IF IF-ELSE, IF-ELSE IF SWITCH,
                        ,                   ,                         Format:
                      WHILE, DO, FOR                                    if    (condition) {
                                                                             Statements if condition is TRUE;
CONDITIONALS                                                            }
IF Statement: A conditional branching statement used to                 else if (condition) {
determine whether a stated condition is TRUE.                              Statements if condition is TRUE;
                                                                        }
Format:
                                                                        else {
  if      (condition)   {
                                                                           Statements if no prior condition is
             statements if condition is TRUE
                                                                             true;
          }
                                                                        }
Example:
  if      (score >= 65”) {
             grade = “Pass”;
             message = “Congratulations”;
  }




                                                                  2
Example:                                                        Example:
  if         (score>=90)         {                                switch (colorchoice)        {
       grade=”A”;                                                   case “red”:
  }                                                                   document.bgColor=”red”;
  else if (score>=80)            {                                    break;
     grade=”B”;                                                     case “blue”:
  }                                                                   document.bgColor=”blue”;
  else if (score>=70)            {                                    break;
     grade=”C”;                                                     default:
  }                                                                   document.bgColor=”white”;
  else if (score>=65)            {                                    break;
     grade=”D”;                                                     }
  }
                                                                LOOPS
  else                           {
     grade=”F”;                                                 Loops cause a segment of code to repeat until a stated
  }                                                             condition is met. You can use any loop format for any
                                                                type of code
SWITCH Statement: An alternative to the IF-ELSE IF
statement for handling multiple options. Compares the           FOR LOOP:
expression to the test values to find a match.                  Format:
Format:                                                           For (intialize; conditional test;
  switch (expression or variable name)                  {              increment/decrement)         {
                                                                     Statements to execute;
       case label:
                                                                  }
           statements if expression matches
                                                                Example:
             this label;
                                                                  For (var i=0; i<=10; i++)          {
           break;
                                                                     document.write (“This is line “ + i);
       case label:
                                                                  }
           statements if expression matches
                                                                DO/WHILE LOOP:
            this label;
                                                                Format:
           break;
       default:                                                   do      {
                                                                       Statements to execute;
           statements if expression does not
                                                                  }
            match any label;
                                                                  while (condition);
           break;
                                                                Example:
       }
                                                                  var i=0;
                                                                  do    {
                                                                     document.write (“This is line “ + i);
                                                                     i++;
                                                                  }
                                                                  while (i <=10);




                                                            3
Initializing Arrays:
WHILE LOOP:
                                                                   Array items can be treated as simple variables:
Format:
                                                                       days[0] = “Sunday”;
  while (condition) {
                                                                       days[1] = “Monday”;
     Statements;
                                                                       etc.
     Increment/decrement;
  }
                                                                   STRING OBJECT
Example:
                                                                   Definition: String object is created by assigning a string to a
  var i = 0;
                                                                   variable, or by using the new object constructor.
  while (i<=10)     {
                                                                   Example:
     document.write (“This is line “ + i);
     i++;                                                              var name = “Carol”;
  }                                                                    var name = new String(“Carol”);
Hint: Watch out for infinite loops, which do not have a            Properties:
stopping condition or have a stopping condition that will                                 returns the number of characters in the
                                                                       Length:
never be reached.                                                                         string
                                                                                          allows the user to add methods and
                                                                       Prototype:
OBJECTS                                                                                   properties to the string
                                                                   Methods:
Definition: Objects are a composite data type which con-
                                                                   String formatting methods (similar to HTML formatting tags)
tain properties and methods. JavaScript contains built-in
                                                                      String.big
objects and allows the user to create custom objects.
                                                                      String.blink
Creating Objects: Use the new constructor
                                                                      String.italics
  var X = new Array()                                              Substring methods (allow user to find, match, or change
Examples:                                                          patterns of characters in the string)
  date, time, math, strings, arrays                                    indexOf()
                                                                       charAt()
ARRAY OBJECT                                                           replace()
Definition: Array object is a variable that stores multiple val-
                                                                   MATH OBJECT
ues. Each value is given an index number in the array and
                                                                   Definition: Math object allows arithmetic calculations not
each value is referred to by the array name and the
                                                                   supported by the basic math operators. Math is a built-in
index number. Arrays, like simple variables, can hold any
                                                                   object that the user does not need to define.
kind of data. You can leave the size blank when you create
an array. The size of the array will be determined by the          Examples:
number of items placed in it.
                                                                                                       returns absolute value of
                                                                       Math.abs(number)
Format:                                                                                                the numeric argument
  var arrayname = new Array(size)                                                                      returns the cosine of the
                                                                       Math.cos(number)
                                                                                                       argument, in radians
Hint: When you create an array, you create a new instance
of the array object. All properties and methods of the array                                           rounds number to the
                                                                       Math.round(number)
object are available to your new array.                                                                nearest integer
Example:
                                                                   DATE/TIME OBJECTS
  var days = new Array (7)
                                                                   Date object provides methods for getting or setting infor-
  This creates an array of seven elements using the array
                                                                   mation about the date and time.
  constructor.
                                                                   Note: Dates before January 1, 1970 are not supported.
  The first item is days[0], the last item is days[6].

                                                                   4
FUNCTIONS                                                          PUTTING IT TOGETHER:
                                                                   JAVASCRIPT AND HTML
Definition: A pre-written block of code that performs a
                                                                   ON THE WEB
specific task. Some functions return values; others perform
a task like sorting, but return no value. Function names
                                                                   Cookies: Text-file messages stored by the browser on the
follow the same rules as variables names. There may or
                                                                   user’s computer
may not be an argument or parameter in the parenthesis,
                                                                   Purpose: To identify the user, store preferences, and present
but the parenthesis has to be there.
                                                                   customized information each time the user visits the page
User-defined Functions:
                                                                   Types:
Example:
                                                                   Temporary (transient, session) — stored in temporary
  ParseInt() or ParseFloat() convert a string to a
                                                                   memory and available only during active browser session
       number.
                                                                   Persistent (permanent, stored) — remain on user’s comput-
To create a function:
                                                                   er until deleted or expired
Format:
                                                                   Browser Detection: A script written to determine which
  function name_of_function (arguments) {
                                                                   browser is running; determine if the browser has the capabili-
      statements to execute when
                                                                   ties to load the webpage and support the javascript code; and,
       function is called;
                                                                   if needed, load alternate javascript code to match the browser
  }
                                                                   and platform.
Example:
                                                                   Sniffing: A script written to determine whether a specific
  function kilosToPounds (){
                                                                   browser feature is present; i.e., detecting the presence of
      pounds=kilos*2.2046;
                                                                   Flash before loading a webpage.
  }
                                                                   Event Handling: Use HTML event attributes (mouseover,
This new function takes the value of the variable kilos,
                                                                   mouse click, etc.) and connect event to a JavaScript function
multiplies it by 2.2046, and assigns the result to the vari-
                                                                   called an event handler
able pounds.
To call a function: Give the name of the function followed
by its arguments, if any
  ParseInt(X); converts the data stored in the variable
       X into a numeric value.
  kilosToPounds(17); converts 17 kilos to the same
       mass in pounds, returning the value 37.4782.


METHODS
Definition: A special kind of function used to describe or
instruct the way the object behaves. Each object type in
JavaScript has associated methods available.
Examples:
  array.sort();
  document.write();
  string.length();
Calling: To call or use a method, state the method name
followed by its parameters in parentheses.
Example:
  document.write(“Hello, world!”);
                                                               5
COMPARISON
OPERATORS
                                                               ==        Returns true if the operands are equal
                                                               !=        Returns true if the operands are not equal
ARITHMETIC
                                                               ===       Returns true if the operands are equal and the
 +    addition         adds two numbers
                                                                         same data type
 –    subtraction      subtracts one number from
                                                               !==       Returns true if the operands are not equal and/or
                       another
                                                                         not the same data type
 *    multiplication   multiplies two numbers
                                                               >         Returns true if the first operand is greater than
 /    division         divides one number by another
                                                                         the second
 %    modulus          returns the integer remainder
                                                               >=        Returns true if the first operand is greater than or
                       after dividing two numbers
                                                                         equal to the second
 ++   increment        adds one to a numeric variable
                                                               <         Returns true if the first operand is less than the
 —    decrement        subtracts one from a numeric
                                                                         second
                       variable
                                                               <=        Returns true if the first operand is less than or
                                                                         equal to the second
STRING
 +    concatenation    concatenates or joins two              ASSIGNMENT
                       strings or other elements
                                                               =         Assigns the value of the seond operand to the
 +=   concatenation/   concatenates two string
                                                                         first operand
      assignment       variables and assigns the
                                                               +=        Adds two numeric operands and assigns the
                       result to the first variable
                                                                         result to the first operand
                                                               –=        Subtracts the second operand from the first, and
LOGICAL
                                                                         assigns the result to the first
 &&   logical AND      Compares two operands;                  *=        Multiplies two operands, assigns the result to the
                       returns true if both are true,                    first
                       otherwise returns false                 /=        Divides the first operand by the second, assigns
 ||   logical OR       Compares two operands;                            the result to the first
                       returns true if either operand          %=        Finds the modulus of two numeric operands, and
                       is true, otherwise returns false                  assigns the result to the first
 !    logical NOT      Returns false if its operand
                       can be converted to true,
                                                              RESERVED WORDS
                       otherwise returns false
                                                              abstract         else            instanceof      switch
                                                              boolean          enum            int             synchronized
                                                              break            export          interface       this
                                                              byte             extends         long            throw
                                                              case             false           native          throws
                                                              catch            final           new             transient
                                                              char             finally         null            true
                                                              class            float           package         try
                                                              const            for             private         typeof
                                                              continue         function        protected       var
                                                              debugger         goto            public          void
                                                              default          if              return          volatile
                                                              delete           implements      shor            while
                                                              do               import          static          with
                                                              double           in              super


                                                          6

More Related Content

Viewers also liked

ПLAB -интерьерные решения
ПLAB -интерьерные решения ПLAB -интерьерные решения
ПLAB -интерьерные решения
Sergey Svetlichnyi
 
EXPD
EXPDEXPD
India Blog Trends 2016
India Blog Trends 2016India Blog Trends 2016
India Blog Trends 2016
Palin Ningthoujam
 
Isaiah 62
Isaiah 62Isaiah 62
Isaiah 62jkenm
 
Spiritual
SpiritualSpiritual
Spiritualjkenm
 
Discipleship
DiscipleshipDiscipleship
Discipleshipjkenm
 
New Creation
New  CreationNew  Creation
New Creationjkenm
 
Partnership for powerful participation
Partnership for powerful participationPartnership for powerful participation
Partnership for powerful participation
hbr.presentation
 
Do Right Thing
Do Right ThingDo Right Thing
Do Right Thing51 lecture
 
javascript reference
javascript referencejavascript reference
javascript reference51 lecture
 
Anatomy
AnatomyAnatomy
Anatomyjkenm
 
Project Proposal Hints
Project  Proposal  HintsProject  Proposal  Hints
Project Proposal Hints
guest6b1035
 
Revelation
RevelationRevelation
Revelationjkenm
 
Top 10 Un-Safety Awards
Top 10 Un-Safety AwardsTop 10 Un-Safety Awards
Top 10 Un-Safety Awards
jamestl2
 
1242982374API2 upload
1242982374API2 upload1242982374API2 upload
1242982374API2 upload51 lecture
 

Viewers also liked (17)

ПLAB -интерьерные решения
ПLAB -интерьерные решения ПLAB -интерьерные решения
ПLAB -интерьерные решения
 
No[1][1]
No[1][1]No[1][1]
No[1][1]
 
EXPD
EXPDEXPD
EXPD
 
Canto budista tibet
Canto budista tibetCanto budista tibet
Canto budista tibet
 
India Blog Trends 2016
India Blog Trends 2016India Blog Trends 2016
India Blog Trends 2016
 
Isaiah 62
Isaiah 62Isaiah 62
Isaiah 62
 
Spiritual
SpiritualSpiritual
Spiritual
 
Discipleship
DiscipleshipDiscipleship
Discipleship
 
New Creation
New  CreationNew  Creation
New Creation
 
Partnership for powerful participation
Partnership for powerful participationPartnership for powerful participation
Partnership for powerful participation
 
Do Right Thing
Do Right ThingDo Right Thing
Do Right Thing
 
javascript reference
javascript referencejavascript reference
javascript reference
 
Anatomy
AnatomyAnatomy
Anatomy
 
Project Proposal Hints
Project  Proposal  HintsProject  Proposal  Hints
Project Proposal Hints
 
Revelation
RevelationRevelation
Revelation
 
Top 10 Un-Safety Awards
Top 10 Un-Safety AwardsTop 10 Un-Safety Awards
Top 10 Un-Safety Awards
 
1242982374API2 upload
1242982374API2 upload1242982374API2 upload
1242982374API2 upload
 

More from 51 lecture

1244600439API2 upload
1244600439API2 upload1244600439API2 upload
1244600439API2 upload51 lecture
 
1242982622API2 upload
1242982622API2 upload1242982622API2 upload
1242982622API2 upload51 lecture
 
1242626441API2 upload
1242626441API2 upload1242626441API2 upload
1242626441API2 upload51 lecture
 
1242625986my upload
1242625986my upload1242625986my upload
1242625986my upload51 lecture
 
1242361147my upload ${file.name}
1242361147my upload ${file.name}1242361147my upload ${file.name}
1242361147my upload ${file.name}51 lecture
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test51 lecture
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test51 lecture
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test51 lecture
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test51 lecture
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test51 lecture
 
this is test api2
this is test api2this is test api2
this is test api2
51 lecture
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!51 lecture
 
Stress Management
Stress Management Stress Management
Stress Management 51 lecture
 
Iim A Managment
Iim A ManagmentIim A Managment
Iim A Managment51 lecture
 
Time Management
Time ManagementTime Management
Time Management51 lecture
 
Conversation By Design
Conversation By DesignConversation By Design
Conversation By Design51 lecture
 
Web 2.0
Web 2.0Web 2.0
Web 2.0
51 lecture
 
dynamics-of-wikipedia-1196670708664566-3
dynamics-of-wikipedia-1196670708664566-3dynamics-of-wikipedia-1196670708664566-3
dynamics-of-wikipedia-1196670708664566-3
51 lecture
 
Tech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM WorkflowsTech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM Workflows
51 lecture
 

More from 51 lecture (20)

1244600439API2 upload
1244600439API2 upload1244600439API2 upload
1244600439API2 upload
 
1242982622API2 upload
1242982622API2 upload1242982622API2 upload
1242982622API2 upload
 
1242626441API2 upload
1242626441API2 upload1242626441API2 upload
1242626441API2 upload
 
1242625986my upload
1242625986my upload1242625986my upload
1242625986my upload
 
1242361147my upload ${file.name}
1242361147my upload ${file.name}1242361147my upload ${file.name}
1242361147my upload ${file.name}
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test
 
this is test api2
this is test api2this is test api2
this is test api2
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
Stress Management
Stress Management Stress Management
Stress Management
 
Iim A Managment
Iim A ManagmentIim A Managment
Iim A Managment
 
Time Management
Time ManagementTime Management
Time Management
 
Conversation By Design
Conversation By DesignConversation By Design
Conversation By Design
 
Web 2.0
Web 2.0Web 2.0
Web 2.0
 
dynamics-of-wikipedia-1196670708664566-3
dynamics-of-wikipedia-1196670708664566-3dynamics-of-wikipedia-1196670708664566-3
dynamics-of-wikipedia-1196670708664566-3
 
Tech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM WorkflowsTech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM Workflows
 
Esb
EsbEsb
Esb
 

Recently uploaded

RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 

Recently uploaded (20)

RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 

Javascript Refererence

  • 1. Addison-Wesley’s JavaScript Reference Card Kathleen M. Goelz and Carol J. Schwartz, Rutgers University Javascript: A scripting language designed to be integrated VARIABLES into HTML code to produce enhanced, dynamic, interac- Definition: A placeholder for storing data. In JavaScript, a tive web pages. declaration statement consists of the reserved word var and the name (identifier) of one or more variables. DATA TYPES Format: Definition: The classification of values based on the specific var variable_name categories in which they are stored. [var command is used to declare (create) variables] Primitive Types: String, Boolean, Integer, Floating Point, Examples: Null, Void var myHouseColor Composite Types: Object, Array, Function. Composite data var myAddress types are in separate sections of the code. var vacation_house, condominium, primaryResidence NUMERIC Rules for Naming Variables: Integer: Positive or negative numbers with no fractional 1. Variables cannot be reserved words. parts or decimal places. 2. Variables must begin with a letter or underscore and Floating Point: Positive or negative numbers that contain a cannot begin with symbols, numbers, or arithmetic decimal point or exponential notations. notations. String: A sequence of readable characters or text, surround- 3. Spaces cannot be included in a variable name. ed by single or double quotes. Hints: Boolean: The logical values True/False, etc. used to com- 1. Although variables in JavaScript can be used without pare data or make decisions. being declared, it is good programming practice to Null: The variable does not have a value; nothing to report. declare (initialize), all variables. Null is not the same as zero, which is a numeric value. 2. Variable names are case sensitive; for example X does Casting: Moving the contents of a variable of one type to a not equal x. variable of a different type. You don’t move the contents to a different variable; it stays in the same variable but the data type is changed or “re-cast”. ,!7IA3C1-dcahfj!:t;K;k;K;k ISBN 0-321-32075-1
  • 2. IF-ELSE Statement: A conditional branching statement INITIALIZING VARIABLES that includes a path to follow if the condition is TRUE and Use the declaration statement to assign a value to the vari- a path to follow if the condition is FALSE. able. The value is on the right of the equal sign; the variable Format: is on the left. if (condition) { Format: statements if condition is TRUE; var variable_name = value } Examples: else { var myHouseColor = “yellow” statements if condition is FALSE; [literal string value yellow assigned to variable } myHouseColor] Example: var myAddress = 473 if (score >= 65) { [numeric value 473 assigned to variable myAddress] grade = “Pass”; var bookTitle = “Time Capsule”, cost = message = “Congratulations”; 28.95, publisher = “Tucker Bay” } [multiple variables can be assigned in one statement] else { grade = “Fail” message = “Try again”; DECISION MAKING AND } CONTROL STRUCTURES IF-ELSE IF Statement: A conditional branching statement Definition: Statements and structures used to change the that allows for more than two possible paths. The first time order in which computer operations will occur. a true condition is encountered, the statement is executed Types: and the remaining conditions will not be tested. Conditional Branching IF IF-ELSE, IF-ELSE IF SWITCH, , , Format: WHILE, DO, FOR if (condition) { Statements if condition is TRUE; CONDITIONALS } IF Statement: A conditional branching statement used to else if (condition) { determine whether a stated condition is TRUE. Statements if condition is TRUE; } Format: else { if (condition) { Statements if no prior condition is statements if condition is TRUE true; } } Example: if (score >= 65”) { grade = “Pass”; message = “Congratulations”; } 2
  • 3. Example: Example: if (score>=90) { switch (colorchoice) { grade=”A”; case “red”: } document.bgColor=”red”; else if (score>=80) { break; grade=”B”; case “blue”: } document.bgColor=”blue”; else if (score>=70) { break; grade=”C”; default: } document.bgColor=”white”; else if (score>=65) { break; grade=”D”; } } LOOPS else { grade=”F”; Loops cause a segment of code to repeat until a stated } condition is met. You can use any loop format for any type of code SWITCH Statement: An alternative to the IF-ELSE IF statement for handling multiple options. Compares the FOR LOOP: expression to the test values to find a match. Format: Format: For (intialize; conditional test; switch (expression or variable name) { increment/decrement) { Statements to execute; case label: } statements if expression matches Example: this label; For (var i=0; i<=10; i++) { break; document.write (“This is line “ + i); case label: } statements if expression matches DO/WHILE LOOP: this label; Format: break; default: do { Statements to execute; statements if expression does not } match any label; while (condition); break; Example: } var i=0; do { document.write (“This is line “ + i); i++; } while (i <=10); 3
  • 4. Initializing Arrays: WHILE LOOP: Array items can be treated as simple variables: Format: days[0] = “Sunday”; while (condition) { days[1] = “Monday”; Statements; etc. Increment/decrement; } STRING OBJECT Example: Definition: String object is created by assigning a string to a var i = 0; variable, or by using the new object constructor. while (i<=10) { Example: document.write (“This is line “ + i); i++; var name = “Carol”; } var name = new String(“Carol”); Hint: Watch out for infinite loops, which do not have a Properties: stopping condition or have a stopping condition that will returns the number of characters in the Length: never be reached. string allows the user to add methods and Prototype: OBJECTS properties to the string Methods: Definition: Objects are a composite data type which con- String formatting methods (similar to HTML formatting tags) tain properties and methods. JavaScript contains built-in String.big objects and allows the user to create custom objects. String.blink Creating Objects: Use the new constructor String.italics var X = new Array() Substring methods (allow user to find, match, or change Examples: patterns of characters in the string) date, time, math, strings, arrays indexOf() charAt() ARRAY OBJECT replace() Definition: Array object is a variable that stores multiple val- MATH OBJECT ues. Each value is given an index number in the array and Definition: Math object allows arithmetic calculations not each value is referred to by the array name and the supported by the basic math operators. Math is a built-in index number. Arrays, like simple variables, can hold any object that the user does not need to define. kind of data. You can leave the size blank when you create an array. The size of the array will be determined by the Examples: number of items placed in it. returns absolute value of Math.abs(number) Format: the numeric argument var arrayname = new Array(size) returns the cosine of the Math.cos(number) argument, in radians Hint: When you create an array, you create a new instance of the array object. All properties and methods of the array rounds number to the Math.round(number) object are available to your new array. nearest integer Example: DATE/TIME OBJECTS var days = new Array (7) Date object provides methods for getting or setting infor- This creates an array of seven elements using the array mation about the date and time. constructor. Note: Dates before January 1, 1970 are not supported. The first item is days[0], the last item is days[6]. 4
  • 5. FUNCTIONS PUTTING IT TOGETHER: JAVASCRIPT AND HTML Definition: A pre-written block of code that performs a ON THE WEB specific task. Some functions return values; others perform a task like sorting, but return no value. Function names Cookies: Text-file messages stored by the browser on the follow the same rules as variables names. There may or user’s computer may not be an argument or parameter in the parenthesis, Purpose: To identify the user, store preferences, and present but the parenthesis has to be there. customized information each time the user visits the page User-defined Functions: Types: Example: Temporary (transient, session) — stored in temporary ParseInt() or ParseFloat() convert a string to a memory and available only during active browser session number. Persistent (permanent, stored) — remain on user’s comput- To create a function: er until deleted or expired Format: Browser Detection: A script written to determine which function name_of_function (arguments) { browser is running; determine if the browser has the capabili- statements to execute when ties to load the webpage and support the javascript code; and, function is called; if needed, load alternate javascript code to match the browser } and platform. Example: Sniffing: A script written to determine whether a specific function kilosToPounds (){ browser feature is present; i.e., detecting the presence of pounds=kilos*2.2046; Flash before loading a webpage. } Event Handling: Use HTML event attributes (mouseover, This new function takes the value of the variable kilos, mouse click, etc.) and connect event to a JavaScript function multiplies it by 2.2046, and assigns the result to the vari- called an event handler able pounds. To call a function: Give the name of the function followed by its arguments, if any ParseInt(X); converts the data stored in the variable X into a numeric value. kilosToPounds(17); converts 17 kilos to the same mass in pounds, returning the value 37.4782. METHODS Definition: A special kind of function used to describe or instruct the way the object behaves. Each object type in JavaScript has associated methods available. Examples: array.sort(); document.write(); string.length(); Calling: To call or use a method, state the method name followed by its parameters in parentheses. Example: document.write(“Hello, world!”); 5
  • 6. COMPARISON OPERATORS == Returns true if the operands are equal != Returns true if the operands are not equal ARITHMETIC === Returns true if the operands are equal and the + addition adds two numbers same data type – subtraction subtracts one number from !== Returns true if the operands are not equal and/or another not the same data type * multiplication multiplies two numbers > Returns true if the first operand is greater than / division divides one number by another the second % modulus returns the integer remainder >= Returns true if the first operand is greater than or after dividing two numbers equal to the second ++ increment adds one to a numeric variable < Returns true if the first operand is less than the — decrement subtracts one from a numeric second variable <= Returns true if the first operand is less than or equal to the second STRING + concatenation concatenates or joins two ASSIGNMENT strings or other elements = Assigns the value of the seond operand to the += concatenation/ concatenates two string first operand assignment variables and assigns the += Adds two numeric operands and assigns the result to the first variable result to the first operand –= Subtracts the second operand from the first, and LOGICAL assigns the result to the first && logical AND Compares two operands; *= Multiplies two operands, assigns the result to the returns true if both are true, first otherwise returns false /= Divides the first operand by the second, assigns || logical OR Compares two operands; the result to the first returns true if either operand %= Finds the modulus of two numeric operands, and is true, otherwise returns false assigns the result to the first ! logical NOT Returns false if its operand can be converted to true, RESERVED WORDS otherwise returns false abstract else instanceof switch boolean enum int synchronized break export interface this byte extends long throw case false native throws catch final new transient char finally null true class float package try const for private typeof continue function protected var debugger goto public void default if return volatile delete implements shor while do import static with double in super 6