You are on page 1of 5

Answers of textbook exercises

Fill in the Blanks

1. S y n t a x refers to a set of rules that determine how the


language will be written (by the programmer) and interpreted(by
the browser).

2. A k e y w o r d is a word that is reserved by a program because


the word has a special meaning.

3. V a r i a b l e s are containers for storing data values.


4. All variables are I dentifiers
5. I d e n t i f i e r is a name given to an entity, which distinctly
identifies an entity in a program at the time of its execution.

State True or False

1. All identifiers are variables. -False


2. Statement is a list of “instructions” to be "executed" by a computer.
-True
3. ; is used for identifying the end of a statement. -True
4. The group of statements inside a curly bracket {...} is called a code
block. -True
5. // is division operator in javascript. -False

Match the Following


1. Creating a variable X=5

2. Variable Containers for storing data


values.

3. Identifier Any entity in a programming


language identified with a name.

4. Statement An executable piece of code.

5. Code blocks Statements grouped together.

Multiple choice questions

1. The following is not an example for variable declaration,


a. var x;
b. var y,m;
c. var age;
d. x * 2;

2. Which of the following are examples for statements?


a. x = y+2;
b. x = 10;
c. y = 10 * x;
d. All of the above

3. _____ separates javascript statements:


a. //
b. ;
c. :
d. None of the above

4. In order to comment a code, the following can be used:


a. //
b. /*...*/
c. Both a and b
d. None of the above

5. An entity which can change its value is called:


a. Variable
b. Keyword
c. Identifier
d. None of the above

Answer in one word or one sentence

1. What is JavaScript syntax?


JavaScript syntax refers to a set of rules that determine how the
language will be written (by the programmer) and interpreted (by
the browser).

2. What is a variable?
JavaScript variables are containers for storing data values.

3. What is an identifier?
All JavaScript entities must be identified with unique names. These
unique names are called identifiers. Identifiers can be short names
(like x and y) or more descriptive names (age, sum etc.).

4. What is a statement?
a statement is a piece of code that the computer can execute.
JavaScript statements are composed of identifiers, operators,
expressions. keywords and comments.

5. What is a code block?


JavaScript statements can be grouped together using curly
brackets {...}. The purpose of code blocks is to group the
statements to be executed together.

Answer the following

1. How can you initialize a variable in JavaScript? Explain with


examples.
JavaScript variables are containers for storing data values.
"Variable" is a mathematical term and it means the same in the
case of programming. An entity which can change its value is a
variable.
Eg:
var a = 625;
var b = 750;
var c= 2*a+b;

2. What are identifiers and how are they different from variables?
Provide examples.
An identifier is a name given to an entity, which distinctly identifies
an entity in a program at the time of its execution. Variable is also
an identifier, its name uniquely identifies itself in a program. Here,
the fundamental difference between an identifier and a variable is
that an identifier is a “name given to an entity” whereas in a
program a variable is a “name given to a memory location” that is
used to hold a value, which may get modified during program
execution. All variables are identifiers. But not all identifiers are
variables. For example, the name of a function is an identifier but
not a variable.
var cyberSquare, cybersquare ;
cyberSquare = “programming world”;
cybersquare = “cyberkid”;
3. What are JavaScript statements? Explain with examples.
A computer program is a sequence of “instructions” to be executed
by a computer. In a programming language, these instructions are
called statements. Alternatively, a statement is a piece of code that
the computer can execute. JavaScript statements are composed of
identifiers, operators, expressions. keywords and comments.
Eg:
var a = 625;
var b = 750;
var c= 2*a+b;

4. How can you comment on a code in JavaScript? Explain with


examples.
A comment is a programmer-readable explanation or annotation in
a computer program. It makes the program easier for humans to
understand, and is generally ignored by compilers and interpreters.
There are 2 types of comments in javascript:
● Double slash (//) is used tor single-line comments
● Multi-line comments are added in between /* and */.
Eg:

5. What is a JavaScript keyword? Explain with examples.


Keywords are English words that are reserved by programming
languages for specific purposes. It is similar to words in a spoken
language. Some of the keywords in JavaScript are given below.
var, function, if, else, do, while, for, switch, break etc…

You might also like