Computer Knowledge

Programming Languages and Compilers

2,284 Questions

Programming languages and compilers involve the rules, syntax, and semantics used to write and execute software programs. Key areas include scripting languages, object oriented concepts, and parsing algorithms like top down parsers. Practice these computer science questions to build proficiency for technical and computer knowledge exams.

Object oriented languagesScripting languagesCompilers and parsersProgramming syntax

Programming Languages and Compilers Questions

Multiple choice

What is the purpose of the join() method in JavaScript arrays?

  1. To join all the elements of an array into a single string

  2. To add an element to the end of an array

  3. To remove the last element from an array

  4. To sort the elements of an array

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The join() method joins all the elements of an array into a single string, separated by a specified separator.

Multiple choice

Which of the following is not a built-in method of JavaScript objects?

  1. hasOwnProperty()

  2. toLocaleString()

  3. valueOf()

  4. forEach()

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The forEach() method is not a built-in method of JavaScript objects. It is a method of the Object.prototype object, which is added to all objects by default.

Multiple choice

What is the purpose of the Object.keys() method in JavaScript?

  1. To return an array of all the keys in an object

  2. To return an array of all the values in an object

  3. To return the number of keys in an object

  4. To return the number of values in an object

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Object.keys() method returns an array of all the keys in an object, in the same order as they were defined.

Multiple choice

Which of the following is not a valid way to access the properties of an object in JavaScript?

  1. object.property

  2. object['property']

  3. object[property]

  4. object.getProperty()

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The object.getProperty() syntax is not a valid way to access the properties of an object in JavaScript. The correct syntax is object.property, object['property'], or object[property].

Multiple choice

What is the purpose of the Array.from() method in JavaScript?

  1. To convert an array-like object to an array

  2. To convert an array to an array-like object

  3. To create a new array with the same elements as an existing array

  4. To sort the elements of an array

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Array.from() method converts an array-like object (such as a string, a NodeList, or an HTMLCollection) to an array.

Multiple choice

Which of the following is not a valid way to iterate over the elements of an array in JavaScript?

  1. for (let i = 0; i < array.length; i++) { ... }

  2. for (const element of array) { ... }

  3. array.forEach((element, index) => { ... })

  4. array.map((element, index) => { ... })

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The array.map() method is not a valid way to iterate over the elements of an array in JavaScript. It is a method that creates a new array with the results of calling a specified function on each element of the original array.

Multiple choice

What is the purpose of the Object.assign() method in JavaScript?

  1. To copy the properties of one object to another

  2. To merge two objects into a new object

  3. To create a new object with the same properties as an existing object

  4. To delete the properties of an object

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Object.assign() method copies the properties of one object to another. It can be used to merge two objects into a new object, or to create a new object with the same properties as an existing object.

Multiple choice

Which of the following is not a valid way to define a JavaScript object?

  1. const object = {};

  2. const object = new Object();

  3. const object = { property: value };

  4. const object = [property: value]

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The const object = [property: value] syntax is not a valid way to define a JavaScript object. The correct syntax is const object = {};, const object = new Object();, or const object = { property: value };.

Multiple choice

Which of the following is not a valid way to access the elements of an object in JavaScript?

  1. object.property

  2. object['property']

  3. object[property]

  4. object.getProperty()

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The object.getProperty() syntax is not a valid way to access the properties of an object in JavaScript. The correct syntax is object.property, object['property'], or object[property].

Multiple choice

What is the purpose of the Array.prototype.reduce() method in JavaScript?

  1. To reduce an array to a single value

  2. To reduce an array to a new array

  3. To reduce an array to an object

  4. To reduce an array to a string

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Array.prototype.reduce() method reduces an array to a single value. The value is determined by a reduce function that is passed to the method.

Multiple choice

Which of the following is not a valid way to create a new JavaScript object?

  1. const object = {};

  2. const object = new Object();

  3. const object = { property: value };

  4. const object = [];

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The const object = []; syntax is not a valid way to create a new JavaScript object. The correct syntax is const object = {};, const object = new Object();, or const object = { property: value };.

Multiple choice

What is the purpose of the Object.freeze() method in JavaScript?

  1. To prevent an object from being modified

  2. To prevent an object from being deleted

  3. To prevent an object from being accessed

  4. To prevent an object from being serialized

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Object.freeze() method prevents an object from being modified. Once an object is frozen, its properties cannot be added, removed, or changed.

Multiple choice

Which of the following is not a valid way to iterate over the properties of an object in JavaScript?

  1. for (const property in object) { ... }

  2. for (const [property, value] of Object.entries(object)) { ... }

  3. object.forEach((property, value) => { ... })

  4. object.map((property, value) => { ... })

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The object.forEach((property, value) =&gt; { ... }) syntax is not a valid way to iterate over the properties of an object in JavaScript. The correct syntax is for (const property in object) { ... }, for (const [property, value] of Object.entries(object)) { ... }, or object.map((property, value) =&gt; { ... }).

Multiple choice

What is the primary programming language used for scripting in Unity?

  1. C#

  2. C++

  3. Java

  4. Python

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Unity primarily uses C# for scripting, although it also supports other languages like JavaScript and Boo.

Multiple choice

Which JavaScript method is used to send an asynchronous HTTP request to a server?

  1. fetch()

  2. XMLHttpRequest()

  3. send()

  4. open()

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The fetch() method is a modern and simplified way to make asynchronous HTTP requests in JavaScript.