- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
 Take a Tour Practice InterviewNew Search by Name or Email Play Games Questions Forum

Exams Attended

Mock Exams

Make Homepage

# JavaScript Interview Questions and Answers

##### Ques 16. What type of variables are in Javascript?

Ans. Must declare variables before they’re used in the program
Declare at the top of the program & terminate each statement with ‘;’
Intialize variables when appropriate
Local variables (declared within a function) destroyed after function exit.
Can only be accessed within the function

Example – Note Assignments
var candyBarPrice = 2.50;
var taxRate = .075;
var candyBarsPurchased;

##### Ques 17. What is Assignment Operator in Javascript?
Ans. Assignment ‘looks like’ equal sign but does NOT behave like it

subTotal = subTotal + 1.50

subTotal ‘is assigned the value’ that is currently in subTotal plus the value of 1.50
##### Ques 18. What is Expression in Javascript?
Ans. An expression is a statement that describes a computation.
Usually look like algebra formulas
total = subTotal * taxRate
Operators (+, -, *, /, etc.) have different levels of precedence, similar to algebra
Don’t rely on it! For clarity, use parentheses.
##### Ques 19. Explain String in Javascript?
Ans. Strings are sequences of keyboard characters enclosed in quotes
“Hello World” or ‘Hello World’

Variables can hold strings
var greeting = “Hello World”

String can be empty, i.e., contain no characters

Use ‘\\’ (escape symbol) to ‘type’ prohibited characters
\\b for backspace, \\n for newline, \\t for tab, \\” for double quote.
##### Ques 20. What is Date class in Javascript? Please explain.
Ans. to create a Date object, use new & supply year/month/day/… as desired

today = new Date(); // sets to current date & time

newYear = new Date(2002,0,1); //sets to Jan 1, 2002 12:00AM

methods include:

newYear.getYear() can access individual components of a date
newYear.getMonth()
newYear.getDay()
newYear.getHours()
newYear.getMinutes()
newYear.getSeconds()
newYear.getMilliseconds()