Skip to content

Latest commit

 

History

History
28 lines (26 loc) · 1.51 KB

File metadata and controls

28 lines (26 loc) · 1.51 KB

Functions, Methodes and Objects

Images

  • Browsers require very detailed instructions about whatwe want them to do. Therefore, complex scripts can runto hundreds (even thousands) of lines. Programmers usefunctions, methods, and objects to organize their code.This chapter is divided into three sections that introduce: 1.FUNCTIONS & Methodes 2.OBJECTS 3.BUILT-IN METHODS

WHAT IS A FUNCTION?

  • Functions let you group a series of statements together to perform a specific task. If different parts of a script repeat the same task, you can reuse the function (rather than repeating the same set of st atements).
  1. Declaring Function

Images 2. Calling a Function Images 3. Declaring Function that need information Images 4. Calling Function that need information Images 5. Getting a single value out of a Function

Images 6- Getting a multiple value out of a Function Images

ANONYMOUS FUNCTIONS & FUNCTION EXPRESSIONS

  • Expressions produce a value. They can be used where values are expected. If a function is placed where a browser expects to see an expression, (e.g., as an argument to a function), then it gets treated as an expression.

IMMEDIATELY INVOKED FUNCTION EXPRESSIONS

  • This way of writing a function is used in several different situations. Often functions are used to ensure that the variable names do not conflict with each other (especially if the page uses more than one script).