JavaScript Quiz 1 - PowerPoint PPT Presentation

1 / 55
About This Presentation
Title:

JavaScript Quiz 1

Description:

18. What is the usual end-of-line punctuation for the string operand to document. ... 35. What relationship is there between the value of the length property of an ... – PowerPoint PPT presentation

Number of Views:801
Avg rating:3.0/5.0
Slides: 56
Provided by: Suthiksh
Category:

less

Transcript and Presenter's Notes

Title: JavaScript Quiz 1


1
JavaScript Quiz 1
  • Dr Suthikshn Kumar

2
1. The major differences between Java and
JavaScript are
  • Support for Object-Oriented Programming with
    javascripts object model being different from
    Java and C
  • Java is strongly typed language and Javascript is
    dynamically typed language
  • Objects in java are static while objects in
    Javascript are dynamic
  • The syntax of the expressions, assignment
    statements and control statements.

3
2. The major uses of JavaScript on the client
side are
  • Client-side JavaScript can serve as an
    alternative for some of what is done with server
    side programming, thus transfer the load from
    often overloaded server to normally underloaded
    clients, thus benefitting all the other clients.
  • Javascripts can be used as an alternative to java
    applets.
  • Events such as button clicks and mouse movememts
    are easiy detected with javascripts, thus they
    can be used to trigger computations and provide
    feedback to the user.
  • Javascripts can make static XHTML documents into
    highly dynamic documents, by modifying CSS
    properties and content of any element displayed
    in XHTML.

4
3. The basic process of event driven computation
  • Actions often are executed in response to actions
    of the users of documents among them mouse clicks
    and form submissions.
  • Supports user interaction through the elements of
    the client display.
  • Is more efficient to perform input data checks
    and carry on the user dialog entirely on the
    client.
  • Saves both server time and internet time.

5
4. The two categories of properties in JavaScript
  • Data property
  • Method property
  • Object property

6
5. Why does JavaScript have two categories of
data variables, primitives and objects.
  • Primitive are used because they often can be
    implemented directly in hardware, resulting in
    faster operations on their values.
  • The more general category of object properties is
    other objects.

7
6. The two ways to embed a JavaScript script in
an XHTML document.
  • Javascript are embedded either directly are
    indirectly in XHTML
  • Directly, they can be included in XHTML using
    ltscriptgt tag with type attribute text/javascript.
  • Indirectly as a file with ltscript type
    text/javascript src tst_number.js /gt

8
7. The two forms of JavaScript Comments
  • //
  • / /
  • lt? gt
  • lt!-- - - gt

9
8. Why are JavaScript scripts are hidden in XHTML
documents by putting them in XHTML comments.
  • There are some browsers still in use that
    recognize the ltscriptgt tag but do not have
    JavaScript interpreters.
  • There are still a few browsers in use that they
    do not recognize ltscriptgt tags. Such browsers
    would display contents of the script element as
    if it were just text.
  • The XHTML comment lt! works as a hiding prelude
    to JavaScript code.
  • The closing comment for Javascript is // -- gt on
    a new line.

10
9. The primitive data types in JavaScript are
  • Number
  • String
  • Boolean
  • Undefined
  • Null

11
10. Do single quoted string literals have any
different characteristics than double quoted
string literals.
  • Yes
  • No

12
11. In what circumstances would a variable have
the value undefined.
  • If a variable does not exist
  • If a variable has been defined but not assigned a
    value

13
12. If the value undefined is used as a Boolean
expression, is it interpreted as true or false.
  • True
  • False
  • undefined

14
13. What purpose do rules of operator precedence
serve in programming languages.
  • The precedence rules of a language specify which
    operator is evaluated first when two operators
    with different precedence are adjacent in an
    expression.
  • It serves no purpose

15
14. What purpose do rules of operator
associativity serve in programming languages.
  • The associativity rules of a language specify
    which operator is evaluated first when two
    operators with the same precedence are adjacent
    in an expression.
  • It serves no purpose
  • One should use parenthesis

16
15. Describe the purpose and characteristics of
NaN
  • Wherever operation results in not a number
  • Error such as division by zero
  • If NaN is compared for equality against any
    number, the comparison fails.
  • NaN is not equal to itself in a comparison.

17
16. Why is parseInt not used more often.
  • If the string does not begin with a valid integer
    literal, NaN is returned.
  • Because of the coercions JavaScript normally
    does, parseInt and parseFloat are not often
    needed.
  • JavaScript interpreter performs several different
    implicit type conversions called coercions. ( for
    ex. 7 3 21).

18
17. What value does typeof return for an object
operand.
  • If the operand is an object, typeof evaluates to
    object.
  • Objects do not have types in javascript.
  • undefined
  • null

19
18. What is the usual end-of-line punctuation for
the string operand to document.write.
  • The only useful puctuation in its parameter is in
    the form of XHTML tags such as ltbr /gt
  • \n

20
19. What is the usual end-of-line punctuation for
the string operand to alert.
  • \n
  • ltbr /gt

21
20. Describe the operation of the prompt method.
  • The prompt method creates a dialog window that
    contains a text box.
  • The text box is used to collect a string of input
    from the user, which prompt returns as its value
  • The window includes two buttons, OK and cancel.
  • Name prompt(What is your name?, )

22
21. A control construct is a
  • Control statement and the statement or compound
    statement whose execution it controls.
  • sequence of statements delimited by braces.

23
22. Must the then clause of an if statement in
JavaScript always be a compound statement.
  • Yes
  • No
  • Can be either simple or compound statement

24
23. The possible forms of control expressions in
JavaScript.
  • Primitive values
  • Relational expression
  • Compound expression

25
24. The difference between and
  • is a relational operator is equal to
  • is also a relational operator is strictly
    equal to
  • and ! operators disallow type conversion of
    either operand.
  • is wrong syntax !

26
25. Explain what short-circuit evaluation of an
expression means.
  • If the value of the first operand of either or
    determines the value of the expression, the
    second operand is not evaluated and the boolean
    operator does nothing.
  • On evaluating certain expressions, there will be
    a short circuit and chip will blow up with smoke!

27
26. The semantics of break statement.
  • The break statement is exactly like in Java and
    C i.e., break
  • It transfers control out of the compound
    statement in which it appears.

28
27. What is the difference between a while
statement and a do-while statement
  • Do-while statement is same as while statement
  • The do-while statement tests for completion is
    logically at the end rather than beginning of the
    loop construct.
  • The body of the do-while is always executed at
    least once.

29
28. What is a JavaScript constructor called.
  • New
  • The new constructor creates the properties that
    characterize the new object.
  • New operator creates a blank object or one with
    no properties.

30
29. What is the difference between a constructor
in Java and one in JavaScript?
  • In java, the new operator creates a particular
    object, meaning an object with a type and
    specific collection of members.
  • In JavaScript, the constructor that is called in
    new expression creates the properties and
    characterize the new object.
  • In Java the constructor initializes members but
    does not create them.
  • In Javascript, the operator creates a blank
    object, or one with no properties.

31
30. What properties does an object created with a
new operator and the object constructor have?
  • New operator creates a blank object or one with
    no properties.
  • The constructor both creates and initializes the
    properties.

32
31. Describe the two ways the properties of an
object can be referenced.
  • The properties of an object are accessed using
    dot notation, in which the first word is the
    object name and the second is the property name.
    object-dot-property notation. As my_car.make
  • The property names of an object can be accessed
    as if they were elements of an array as
    my_carmake

33
32. How is a new property object created.
  • A property for an object is created by assigning
    a value to that property. For example
  • Var my_car new Object()
  • my_car.make Ford
  • my_car.model SVT

34
33. Describe the semantics of the for-in statement
  • for ( identifier in object ) statement or
    compound statement
  • Example for( var prop in my_car )
  • Document.write( Name , prop, Value ,
    my_carprop, ltbr /gt)
  • The variable prop takes on the values of the
    properties of the my_car object one for each
    iteration.

35
34. The ways an Array object can be created are
  • With new operator and a call to a contructor as
    var my_list new Array( 1,2, Three )
  • The Array object is created with literal values
    ie, var my_list 1, 2, Three

36
35. What relationship is there between the value
of the length property of an Array object and the
actual number of existing elements in the object.
  • The length of an array is both read- and write-
    accessible through the length property
  • Length of an array can be set to whatever one
    likes such as my_list.length 100
  • Only the assigned elements of an array actually
    occupy space.
  • Length property of an array is not necessarily
    the number of defined or even allocated elements.

37
36. Describe the semantics of the join method of
Array
  • The join method converts all of the elements of
    an array to strings and catenates them into a
    single string.
  • If no parameter is provided to join , the values
    in the new string are separated by commas.
  • Ex var names new ArrayMary, Murray,
    Max
  • Var name_string names.join( )
  • Results in Mary Murray Max

38
37. Describe the semantics of the slice method
when it is given just one parameter.
  • The slice method does for arrays what the
    substring method does for string.
  • It returns the part of the Array object specified
    by its parameters which are used as substrings.
  • If the slice is given just one parameter, the
    returned array has all the elements of the object
    starting with the specified index.
  • Ex var list Bill, Will, Jill
  • Var listette list.slice(1)
  • Listette Will, Jill

39
38. What is the form of nested array literal?
  • A two dimensional array is implemented in
    JavaScript as an array of arrays.
  • This can be done with new operator or with nested
    array of literals
  • Var nested_array 2, 4, 6, 1, 3, 5, 10,
    20, 30

40
39. What value is returned by a function that
contains no return statement?
  • A return statement resturns control from the
    function in which it appears to the functions
    caller.
  • It optionally includes an expression whose value
    is returned by the function.
  • If there are no return statements, the returned
    value is undefined.

41
40. Define the scope of a variable in a
JavaScript script embedded in an XHTML document
when the variable is not declared in a function.
  • The scope of a variable is the range of
    statements over which it is visible.
  • When the JavaScript is embedded in an XHTML
    document, the scope of a variable is the range of
    lines of the document over which the variable is
    visible.
  • Variables that are not declared with a var
    statement are implicitly declared by the
    Javascript interpreter at the time it is first
    encountered in the script.
  • Variables that are implicitly declared even if
    the implicit declaration occurs within a function
    definition, have global scope, that is they are
    visible in the entire XHTML document.

42
41. Is it possible to reference global variables
in a JavaScript function.
  • If a variable that is defined both as a local
    variable and as a global variable appears in a
    function, the local variable has precedence.
  • This effectively hides the global variable with
    the same name.

43
42. What is the advantage of using local
variables in a function
  • When the names of the local variables are
    decided, the programmer need not be concerned
    that a global variable with the same name may
    exist somewhere in the collection of scripts in
    the XHTML document.
  • If a variable that is defined as a local variable
    and as a global variable appears in a function,
    the local variable has precedence.
  • This hides the global variable with the same name.

44
43. What parameter-passing method does JavaScript
use?
  • JavaScript uses pass-by-value parameter-passing
    method.
  • When a function is called, the values of the
    actual parameters specified in the call are in
    effect, copied into their corresponding formal
    parameters, which behave exactly like local
    variables.
  • References are passed as the actual parameters
    for objects, the function has access to the
    objects and can change them.

45
44. Does JavaScript check the types of actual
parameters against the types of their
corresponding formal parameters.
46
45. How can a function access actual parameter
values for those actual parameters that do not
correspond to any formal parameters.
  • All parameters are communicated through a
    property array, arguments which like other
    objectsm has a property named, length.
  • By accessing arguments.length, a function can
    determine the number of actual parameters that
    were passed.
  • Because the arguments array is accessible
    directly, all actual parameters specified in the
    call are available. Including actual parameters
    that do not correspond to any formal parameters.

47
46. What is one way in which primitive variables
can be passed by reference to a function.
  • One way is to put the value in an arrat and pass
    the array.
  • Another way to have a function change the value
    of a primitive type actual parameter is to have
    the function return the new value

48
47. What exactly does a constructor do in
JavaScript
  • JavaScript constructors are special methods that
    create and initialize the properties for newly
    created objects.
  • Every new expression must include a call to a
    constructor whose name is the same as the object
    being created.
  • My_car new car(Ford, SVT, 2000)

49
48. What is a character class in a pattern.
50
49. What are the predefined character classes and
what do they mean.
51
50. What are the symbolic quantifiers and what do
they mean.
52
51. Describe the two end-of-line anchors
53
52. What does the I pattern modifier do
54
53. What exactly does the String method replace
do?
55
54. What exactly does the String method match do?
Write a Comment
User Comments (0)
About PowerShow.com