JavaScript Flashcards

1
Q

Which command syntax available in Php isn’t supported by Javascript ?

A

(single line command) is not supported by JavaScript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to define a variable ? How is it different from Php ??

A

var variableName;

In PHP, variable name starts with $.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create an array and point out the difference with PHP array ?

A
var myVariable = [1, “Bob”,”Stev”,10 ]; 
var names= new Array("Tony", "Mike", "Dan");
// load array by putting values in round brackets
alert("Second element of array is: "+names[1]);
// index 1 will get 2nd element in array

In PHP, $fruits = array(“Apple”, “Grapes”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

String concatenation

A

x= “The answer is “ + 42 //The answer is 42

In PHP, “The answer is “. 42

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

querySelector()

A

Returns the first match of the <h1> tag and stores result in a Variable</h1>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

querySelectorAll()

A

Returns all matches of the <h1> tags and stores result in myVariable </h1>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

getElementsByTagName()

A

document.getElementsByTagName(‘p’);

Will get all the <p> tags in the HTML page </p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

getElementById()

A

document.getElementById(custName)

Locates the element whose ID name is custName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

parseInt()

A
  • Parses a string argument
  • Extracts integer from start of string
  • Ignores leading whitespaces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

parstInt() and radix examples

A

parseInt(“F”, 16); // treats it as base 16 and returns 15
parseInt(“1111”, 2); // treats it as base 2 and returns 15
parseInt(“546”, 2); // returns NaN as digits of string are not valid for binary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

parseFloat()

A

similar to parseInt, but returns a floating point number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Number()

A

converts numeric strings to numbers – integer or float. Ignores leading whitespaces
Number(“12”);// returns 12
Number(“12.3”);// returns 12.3
Number(“12px”);// returns NaN due to present of non
-numeric values in the string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Math.max()

Math.min()

A

Returns the largest of a given set of numbers

Returns the smallest of a given set of numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Math.round()

A

Returns the value of a number, rounded to the nearest integer
Math.round( 20.49); // returns 20
Math.round(20.5); // returns 21

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

alert vs prompt

A

alert is just to display the msg
prompt is two-way ie. to give msg and get answer from user
var num1=prompt(“enter first num “);
var num2=prompt(“enter second num”);
var ans=num1*num2;
alert(“The answer on multiplying your numbers is “+ans);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to add an element to an array ?

A

names[3]=”Tina”;

We just added another a 4th element to the end of array

17
Q

find the length of the string in JavaScript ? Is it variable.length or strlength(variable) ?

A

variable.length;

18
Q

toUpperCase() and toLowerCase()

A

string is converted to upper/lower case

19
Q

sub string = starts on 1st, end on 4th, not including 4th is

A

myCountry.substring(0,3)

20
Q

how to sort and reverse the sort, of the elements in an array ?

A

array. sort(); //to sort

array. reverse(); //to reverse