WEEK 12 Flashcards
(22 cards)
The ___ are used to iterate the piece of code using for, while, do while or for-in loops. It makes the code compact. It is mostly
used in array.
JavaScript loops
There are four types of loops in JavaScript.
- for loop
- while loop
- do-while loop
- for-in loop
The ___ iterates the elements for the fixed number of times. It
should be used if number of iteration is known.
JavaScript for loop
The ___ iterates the elements for the infinite number of times. It should be used if number of iteration is not known.
JavaScript while loop
It iterates the elements for the infinite number of times like while loop. But, code is executed at least once whether condition is
true or false.
JavaScript do while loop
___ are used to perform operations. We can call JavaScript
function many times to reuse the code.
JavaScript Functions
Advantage of JavaScript function
- Code reusability
- Less coding
We can call a function several times so it save coding.
Code reusability
It makes our program compact. We don’t need to write many
lines of code each time to perform a common task.
Less coding
We can call function by passing arguments.
JavaScript Function Arguments -
We can call function that returns a value and use
it in our program.
Function with Return Value
In JavaScript, the purpose of Function constructor is to create a new Function object. It executes the code globally.
However, if we call the constructor directly, a function is created dynamically but in an unsecured way.
JavaScript Function Object
It represents the function definition.
functionBody
It is used to call a function contains this value and a single array of arguments
apply ()
It is used to create a new function.
bind()
It is used to call a function contains this value and an argument list
call()
It returns the result in form of a string
toString
___ is an object that represents a collection of
similar type of elements.
JavaScript Array -
There are 3 ways to construct array in JavaScript
- JavaScript array literal
- JavaScript Array directly (new keyword)
- JavaScript array constructor (new keyword) -
The syntax of creating array using array literal is
given as:
var arrayname=[value1,value2…..valueN];
As you can see, values are contained inside [ ] and separated by , (comma).
JavaScript array literal
var arrayname=new Array();
JavaScript Array directly (new keyword)
You need to create instance of array by passing arguments in constructor so that we don’t have to provide value explicitly.
JavaScript array constructor (new keyword)