Basic And Variables — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Basic And Variables — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The development environment offers which standard construct for data validation
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All these facilities are available in JavaScript. Additionally, all development environments provide syntax to create and use memory variables, constants, and functions.
💡Key Conceptual Anchor:Basic And Variables
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The main purpose of a “Live Wire” in NetScape is to
Correct Answer: Option B — Permit server side, JavaScript code, to connect to RDBMS
Detailed Academic Explanation:
A Live Wire database driver also supports a number of non-relational databases.
💡Key Conceptual Anchor:Basic And Variables
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The script tag must be placed in
Correct Answer: Option B — head and body
Detailed Academic Explanation:
If the script tag is placed after the body tag, then, it will not be evaluated at all. Also, it is always recommended and effective to use the script snippet in the <head> tag.
💡Key Conceptual Anchor:Basic And Variables
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
JavaScript is ideal to
Correct Answer: Option B — minimize storage requirements on the web server
Detailed Academic Explanation:
To minimize storage requirements, JavaScript is always a better say.
💡Key Conceptual Anchor:Basic And Variables
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which attribute is used to specify that the script is executed when the page has finished parsing ( only for external scripts )
Correct Answer: Option C — defer
Detailed Academic Explanation:
In order to load a page, the browser must parse the contents of all script tags, which adds additional time to the page load) By minimizing the amount of JavaScript needed to render the page, and deferring parsing of unneeded JavaScript until it needs to be executed, you can reduce the initial load time of your page.
💡Key Conceptual Anchor:Basic And Variables
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
JavaScript can be written
Correct Answer: Option D — all of the mentioned
Detailed Academic Explanation:
JavaScript is a versatile programming language that can be written in various ways depending on the context and requirements. The correct answer is all of the mentioned options. Let's break down each option: Option A, "directly into JS file and included into HTML," refers to writing JavaScript code in a separate JS file with a .js extension and then linking that file to an HTML page using the script tag. This is a common approach to organize and reuse JavaScript code. Option B, "directly on the server page," implies writing JavaScript code within a server-side scripting language like PHP, ASP, or Node.js. In this case, the JavaScript code is processed on the server before sending the response to the client. Option C, "directly into HTML pages," involves writing JavaScript code directly within the script tags in an HTML file. This allows for inline scripting and is suitable for small-scale applications or quick prototyping. Therefore, option D, "all of the mentioned," is the correct answer as JavaScript can be written in JS files, included in HTML, written on the server page, or directly into HTML pages based on the specific requirements of the project.
💡Key Conceptual Anchor:Basic And Variables
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following Attribute is used to include External JS code inside your HTML Document
Correct Answer: Option A — src
Detailed Academic Explanation:
A ”src” attribute could be used to add any external code into the HTML document.
💡Key Conceptual Anchor:Basic And Variables
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The type of a variable that is volatile is
Correct Answer: Option B — Mutable variable
Detailed Academic Explanation:
The variables whose values can be changed are called mutable variable types.
💡Key Conceptual Anchor:Basic And Variables
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
A hexadecimal literal begins with
Correct Answer: Option C — Both 0x and 0X
Detailed Academic Explanation:
Generally, X or x denotes hexadecimal values. So, any integer literal that begins with 0X or 0x denotes a hexadecimal number.
💡Key Conceptual Anchor:Basic And Variables
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The generalised syntax for a real number representation is
Correct Answer: Option A — [digits][.digits][(E|e)[(+|-)]digits]
Detailed Academic Explanation:
Floating-point literals may also be represented using exponential notation: a real number followed by the letter e (or E), followed by an optional plus or minus sign, followed by an integer exponent. This notation represents the real number multiplied by 10 to the power of the exponent.
💡Key Conceptual Anchor:Basic And Variables
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
When there is an indefinite or an infinity value during an arithmetic value computation, javascript
Correct Answer: Option C — Displays “Infinity”
Detailed Academic Explanation:
When the result of a numeric operation is larger than the largest representable number (overflow), the result is a special infinity value, which JavaScript prints as Infinity. Similarly, when a negative value becomes larger than the largest representable negative number, the result is negative infinity, printed as -Infinity. The infinite values behave as you would expect: adding, subtracting, multiplying, or dividing them by anything results in an infinite value (possibly with the sign reversed.
💡Key Conceptual Anchor:Basic And Variables
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not considered as an error in JavaScript?
Correct Answer: Option C — Division by zero
Detailed Academic Explanation:
Division by zero is not an error in JavaScript: it simply returns infinity or negative infinity. There is one exception, however: zero divided by zero does not have a welldefined value, and the result of this operation is the special not-a-number value, printed as NaN.
💡Key Conceptual Anchor:Basic And Variables
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The escape sequence ‘f’ stands for
Correct Answer: Option D — Form feed
Detailed Academic Explanation:
f is the JavaScript escape sequence that stands for Form feed (u000C).
💡Key Conceptual Anchor:Basic And Variables
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The snippet that has to be used to check if “a” is not equal to “null” is
Correct Answer: Option D — if(a!==null)
Detailed Academic Explanation:
The not-equal operator !== compares o to null and evaluates to either true or false.
💡Key Conceptual Anchor:Basic And Variables
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The statement a===b refers to
Correct Answer: Option C — Both a and b are equal in value and type
Detailed Academic Explanation:
a==b returns a true if a and b refer to the same objec ,so they are equal, else it returns a false.
💡Key Conceptual Anchor:Basic And Variables
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Assume that we have to convert “false” that is a non-string to string. The command that we use is (without invoking the “new” operator)
Correct Answer: Option D — Both false.toString() and String(false)
Detailed Academic Explanation:
A non-string can be converted in two ways without using a new operator. false.toString() and String(false).
💡Key Conceptual Anchor:Basic And Variables
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
A function definition expression can be called
Correct Answer: Option B — Function literal
Detailed Academic Explanation:
A function definition expression is a “function literal” in the same way that an object initializer is an “object literal.” A Function definition expression typically consists of the keyword function followed by a comma-separated list of zero or more identifiers (the parameter names) in parentheses and a block of JavaScript code (the function body) in curly braces.
💡Key Conceptual Anchor:Basic And Variables
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The property of a primary expression is
Correct Answer: Option A — stand-alone expressions
Detailed Academic Explanation:
The simplest expressions, known as primary expressions, are those that stand alone — they do not include any simpler expressions. Primary expressions in JavaScript are constant or literal values, certain laguage keywords, and variable references.
💡Key Conceptual Anchor:Basic And Variables
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following statements var text = "testing: 1, 2, 3" ; // Sample text var pattern = /d+/ g // Matches all instances of one or more digits In order to check if the pattern matches with the string “text”, the statement is
Correct Answer: Option D — pattern.test(text)
Detailed Academic Explanation:
The given pattern is applied on the text given in the parenthesis.
💡Key Conceptual Anchor:Basic And Variables
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The JavaScript’s syntax calling ( or executing ) a function or method is called
Correct Answer: Option C — Invocation expression
Detailed Academic Explanation:
An invocation expression is JavaScript’s syntax for calling (or executing) a function or method) It starts with a function expression that identifies the function to be called.
💡Key Conceptual Anchor:Basic And Variables
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What kind of an expression is “new Point(2,3)”?
Correct Answer: Option B — Object Creation Expression
Detailed Academic Explanation:
An object creation expression creates a new object and invokes a function (called a constructor) to initialize the properties of that object. Object creation expressions are like invocation expressions except that they are prefixed with the keyword new.
💡Key Conceptual Anchor:Basic And Variables
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the operator is used to test if a particular property exists or not?
Correct Answer: Option A — in
Detailed Academic Explanation:
The operator “in” tests whether a particular property exists.
💡Key Conceptual Anchor:Basic And Variables
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Among the following, which one is a ternary operator?
Correct Answer: Option D — ?:
Detailed Academic Explanation:
A ternary operator is a conditional operator that takes three operands. In JavaScript, ?: is the ternary operator. It is used for conditional expressions. The syntax is condition ? expr1 : expr2 . Options + , : , and - are not ternary operators.
💡Key Conceptual Anchor:Basic And Variables
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
“An expression that can legally appear on the left side of an assignment expression.” is a well known explanation for variables, properties of objects, and elements of arrays. They are called
Correct Answer: Option C — Lvalue
Detailed Academic Explanation:
lvalue is a historical term that means “an expression that can legally appear on the left side of an assignment expression.” In JavaScript, variables, properties of objects, and elements of arrays are lvalues.
💡Key Conceptual Anchor:Basic And Variables
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
JavaScript is a _______________ language
Correct Answer: Option D — Object-Based
Detailed Academic Explanation:
JavaScript is not a full-blown OOP (Object-Oriented Programming) language, such as Java or PHP, but it is an object-based language.
💡Key Conceptual Anchor:Basic And Variables
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The output for the following code snippet would most appropriately be var a = 5 , b = 1 var obj = { a : 10 } with( obj ) { alert ( b ) }
Correct Answer: Option C — 1
Detailed Academic Explanation:
The interpreter checks obj for property b, fails and takes it from outside of with.
💡Key Conceptual Anchor:Basic And Variables
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
A conditional expression is also called a
Correct Answer: Option B — Immediate if
Detailed Academic Explanation:
A conditional expression in JavaScript is also known as an immediate if or ternary operator . The correct answer is option B. Let's understand the other options: Option A, "Alternate to if-else," is not an accurate description of a conditional expression. While a conditional expression can be used as an alternative to if-else in certain cases, it is not its primary name. Option C, "If-then-else statement," is not the commonly used term for a conditional expression. It is more commonly used to refer to the traditional if-else statement structure. Option D, "None of the mentioned," is incorrect because a conditional expression does have a specific name. Therefore, option B, "Immediate if," is the correct answer as it accurately describes the conditional expression in JavaScript. It is called "immediate" because it allows for a concise way of expressing a condition and immediately returning a value based on that condition.
💡Key Conceptual Anchor:Basic And Variables
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which is a more efficient code snippet ? Code 1 : for(var num = 10 ;num >= 1 ;num -- ) { document . writeln ( num ) ; } Code 2 : var num = 10 ; while( num >= 1 ) { document . writeln ( num ) ; num ++ ; }
Correct Answer: Option A — Code 1
Detailed Academic Explanation:
A for loop is always more efficient because it encapsules two individual statements(initialization and expression) within the braces.
💡Key Conceptual Anchor:Basic And Variables
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
A statement block is a
Correct Answer: Option D — block that combines multiple statements into a single compound statement
Detailed Academic Explanation:
A statement block is a block that combines more than one statements into a single compound statement for ease.
💡Key Conceptual Anchor:Basic And Variables
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
When an empty statement is encountered, a JavaScript interpreter
Correct Answer: Option A — Ignores the statement
Detailed Academic Explanation:
The JavaScript interpreter takes no action when it executes an empty statement. The empty statement is occasionally useful when you want to create a loop that has an empty body.
💡Key Conceptual Anchor:Basic And Variables
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The “var” and “function” are
Correct Answer: Option B — Declaration statements
Detailed Academic Explanation:
The var and function are declaration statements—they declare or define variables and functions. These statements define identifiers (variable and function names) that can be used elsewhere in your program and assign values to those identifiers.
💡Key Conceptual Anchor:Basic And Variables
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following statements switch( expression ) { statements } In the above switch syntax, the expression is compared with the case labels using which of the following operator(s) ?
Correct Answer: Option D — ===
Detailed Academic Explanation:
When a switch executes, it computes the value of expression and then looks for a case label whose expression evaluates to the same value (where sameness is determined by the === operator).
💡Key Conceptual Anchor:Basic And Variables
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet function printArray ( a ) { var len = a . length, i = 0 ; if ( len == 0 ) console . log (" Empty Array ") ; else { do { console . log ( a [ i ]) ; } while ( ++ i < len ) ; } } What does the above code result?
Correct Answer: Option A — Prints the numbers in the array in order
Detailed Academic Explanation:
The do/while loop is less commonly used when compared to the while loop. Here, it prints from the array in the given order.
💡Key Conceptual Anchor:Basic And Variables
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What are the three important manipulations done in a for loop on a loop variable?
Correct Answer: Option B — Initialization,Testing, Updation
Detailed Academic Explanation:
In a for loop, the initialization, the test, and the update are the three crucial manipulations of a loop variable.
💡Key Conceptual Anchor:Basic And Variables
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet function tail ( o ) { for (; o . next; o = o . next ) ; return o; } Will the above code snippet work? If not, what will be the error?
Correct Answer: Option C — Yes, this will work
Detailed Academic Explanation:
The above code uses a for loop to traverse a linked list data structure and return the last object in the list. This will perfectly work.
💡Key Conceptual Anchor:Basic And Variables
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
One of the special feature of an interpreter in reference with the for loop is that
Correct Answer: Option A — Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property
Detailed Academic Explanation:
Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property (a string value) to it.
💡Key Conceptual Anchor:Basic And Variables
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will happen if the body of a for/in loop deletes a property that has not yet been enumerated?
Correct Answer: Option C — That property will not be enumerated
Detailed Academic Explanation:
If the body of a for/in loop deletes a property that has not yet been enumerated, that property will not be enumerated. If the body of the loop defines new properties on the object, those properties will generally not be enumerated.
💡Key Conceptual Anchor:Basic And Variables
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the step of the interpreter in a jump statement when an exception is thrown?
Correct Answer: Option C — The interpreter jumps to the nearest enclosing exception handler
Detailed Academic Explanation:
When an exception is thrown in a jump statement, the interpreter jumps to the nearest enclosing exception handler, which may be in the same function or up the call stack in an invoking function.
💡Key Conceptual Anchor:Basic And Variables
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet while ( a != 0 ) { if (spam>a == 1 ) continue; else a ++ ; } What will be the role of the continue keyword in the above code snippet?
Correct Answer: Option C — The continue keyword skips the rest of the statements in that iteration
Detailed Academic Explanation:
Instead of exiting a loop like the break keyword, the continue keyword moves to the next iteration from the place encountered.
💡Key Conceptual Anchor:Basic And Variables
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code snippet function f ( o ) { if ( o === undefined ) debugger; } What could be the task of the statement debugger?
Correct Answer: Option A — It does nothing but a simple breakpoint
Detailed Academic Explanation:
The debugger statement normally does nothing. If, however, a debugger program is available and is running, then an implementation may (but is not required to) perform some kind of debugging action. In practice, this statement acts like a breakpoint: execution of JavaScript code stops and you can use the debugger to print variable’s values.
💡Key Conceptual Anchor:Basic And Variables
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.