













































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This practice exam focuses on JerryScript, a lightweight JavaScript engine for IoT and embedded systems. Topics include memory constraints, bytecode execution, API embedding, module loading, low-level optimization, device integration, security constraints, and cross-compilation. Candidates design constrained JS applications, measure memory usage, debug runtime issues, and integrate JerryScript with embedded hardware.
Typology: Exams
1 / 85
This page cannot be seen from the preview
Don't miss anything!














































































Question 1. Which of the following best describes the primary design goal of JerryScript? A) To provide a full ES2021 engine for desktop browsers. B) To run JavaScript on devices with less than 64 KB RAM and 200 KB ROM. C) To replace the V8 engine in Node.js. D) To support just-in-time compilation on high‑end CPUs. Answer: B Explanation: JerryScript is intentionally lightweight, targeting micro‑controllers with severe memory constraints (≤ 64 KB RAM, ≤ 200 KB ROM). Question 2. In JerryScript, what does the “snapshot” feature accomplish? A) It records a debugging session. B) It stores the current heap state for later restoration. C) It pre‑compiles JavaScript source into bytecode to reduce RAM usage at startup. D) It creates a visual representation of the call stack. Answer: C Explanation: Snapshots are bytecode images generated ahead‑of‑time; loading them avoids parsing and reduces RAM consumption. Question 3. Which build configuration option would you disable to obtain the smallest possible binary size? A) JERRY_ENABLE_REGEXP_BUILTIN B) JERRY_ENABLE_DATE_BUILTIN C) JERRY_ENABLE_JSON_BUILTIN D) All of the above Answer: D
Explanation: Disabling built‑ins such as RegExp, Date, and JSON removes associated code, shrinking the binary. Question 4. What is the effect of selecting the “Minimal” profile when building JerryScript? A) Enables all ECMAScript features. B) Includes only core language features, omitting optional built‑ins. C) Adds support for WebAssembly. D) Optimizes for maximum performance on desktop CPUs. Answer: B Explanation: The Minimal profile contains the essential ES5.1 core, leaving out optional features to keep size low. Question 5. Which function must be called before any other JerryScript API function? A) jerry_cleanup() B) jerry_init() C) jerry_parse() D) jerry_run() Answer: B Explanation: jerry_init() initializes the engine and must precede all other API calls. Question 6. After finishing work with a JerryScript value, which function should be used to release it? A) jerry_value_free() B) jerry_value_release() C) jerry_value_dispose() D) jerry_value_destroy()
D) jerry_external_function(handler) Answer: C Explanation: jerry_create_external_function() registers a C callback as a JavaScript callable function. Question 10. When a native function receives arguments from JavaScript, which API call obtains the first argument? A) jerry_get_argument(0) B) jerry_get_arg_val(arguments, 0) C) jerry_get_arg(arguments, 0) D) jerry_value_get_argument(arguments, 0) Answer: A Explanation: jerry_get_argument() fetches the argument at the given index from the arguments list. Question 11. Which of the following is NOT a valid jerry_value_t type? A) Undefined B) Null C) Symbol D) Bytecode Answer: D Explanation: Bytecode is not a value type; it is an internal representation of compiled code. Question 12. What does the function jerry_heap_gc() do? A) Compiles JavaScript source to bytecode. B) Forces a garbage‑collection cycle.
C) Returns the current heap size. D) Enables just‑in‑time compilation. Answer: B Explanation: jerry_heap_gc() triggers the mark‑and‑sweep garbage collector manually. Question 13. Which pointer compression scheme does JerryScript use on 32‑bit architectures? A) 8‑bit offsets B) 16‑bit compressed pointers C) 24‑bit pointers D) No compression is used. Answer: B Explanation: JerryScript employs 16‑bit compressed pointers to reduce object reference size on 32 ‑bit targets. Question 14. In the JerryScript VM, what is the role of the “literal store”? A) Holds compiled bytecode. B) Stores reusable constant strings and numbers. C) Manages the call stack. D) Contains debugging symbols. Answer: B Explanation: The literal store deduplicates constant literals to save memory. Question 15. Which API function evaluates a JavaScript source string and returns the result? A) jerry_parse_and_run()
A) false B) true C) undefined D) throws an exception Answer: B Explanation: In JavaScript, functions are objects; the API reflects this. Question 19. Which of the following is the correct order to evaluate a script using the modular API? A) jerry_parse() → jerry_run() → jerry_cleanup() B) jerry_parse() → jerry_run() → jerry_free_value() C) jerry_eval() → jerry_release() → jerry_cleanup() D) jerry_parse() → jerry_release() → jerry_run() Answer: B Explanation: jerry_parse() returns a compiled function value, jerry_run() executes it, and the returned value must be freed with jerry_value_free(). Question 20. Which macro is used to check if a jerry_value_t is a native error object? A) jerry_error_is_native(val) B) jerry_value_is_native_error(val) C) jerry_is_error(val) D) jerry_value_is_error(val) Answer: D Explanation: jerry_value_is_error() works for both native and JavaScript‑thrown errors.
Question 21. When creating a native function, which argument provides the number of arguments passed from JavaScript? A) args_cnt B) argc C) args_num D) length Answer: B Explanation: The handler receives an argc parameter indicating the argument count. Question 22. Which API call converts a C string to a JavaScript string value? A) jerry_string_from_cstring() B) jerry_create_string() C) jerry_string_create() D) jerry_string_new() Answer: B Explanation: jerry_create_string() creates a JavaScript string from a UTF‑8 C string. Question 23. Which of the following is a valid way to throw a RangeError from native code? A) jerry_throw_range_error(message) B) jerry_create_error(JERRY_ERROR_RANGE, message) C) jerry_raise_range_error(message) D) jerry_error_throw(JERRY_ERROR_RANGE, message) Answer: B Explanation: jerry_create_error() creates a standard Error object; the first argument selects the error type.
Explanation: jerry_get_memory_stats() fills a struct with detailed heap usage data. Question 27. In the context of JerryScript, what does “on‑device compilation” refer to? A) Compiling C source code on the MCU. B) Parsing JavaScript and generating bytecode directly on the target microcontroller. C) Translating WebAssembly to native code at runtime. D) Using an external server to compile scripts. Answer: B Explanation: JerryScript can parse and compile JavaScript to bytecode on the device itself, avoiding pre‑compilation. Question 28. Which of the following is NOT a standard built‑in object that can be optionally disabled? A) Math B) JSON C) Date D) RegExp Answer: A Explanation: The Math object is always present; the others can be omitted via build options. Question 29. Which API function is used to set a property on a JavaScript object from C? A) jerry_set_property(obj, key, value) B) jerry_object_set(obj, key, value) C) jerry_set_property_value(obj, key, value) D) jerry_object_set_prop(obj, key, value)
Answer: A Explanation: jerry_set_property() assigns a property value to an object. Question 30. When evaluating code with jerry_eval(), which flag enables strict mode parsing? A) JERRY_PARSE_STRICT_MODE B) JERRY_EVAL_STRICT_MODE C) JERRY_PARSE_STRICT_MODE (passed as third argument) D) JERRY_EVAL_STRICT (passed as options) Answer: C Explanation: The third argument to jerry_eval() is an options mask; JERRY_PARSE_STRICT_MODE enables strict parsing. Question 31. What does the function jerry_value_is_boolean(val) return for a non‑boolean value? A) true B) false C) throws an exception D) undefined Answer: B Explanation: It simply returns false when the value is not a Boolean. Question 32. Which of the following correctly frees a JavaScript value returned by jerry_eval()? A) jerry_release_value(val) B) jerry_value_free(val)
C) As a string of digits. D) As a 16‑bit fixed‑point value. Answer: A Explanation: Numbers follow the ECMAScript specification and are stored as 64‑bit doubles. Question 36. Which function is used to create a JavaScript object from native code? A) jerry_create_object() B) jerry_new_object() C) jerry_object_create() D) jerry_object_new() Answer: A Explanation: jerry_create_object() returns a new empty JavaScript object. Question 37. Which macro determines whether a jerry_value_t is a native (C) pointer? A) jerry_value_is_external(val) B) jerry_value_is_pointer(val) C) jerry_value_is_external_pointer(val) D) jerry_value_is_external(val) (the correct macro) Answer: D Explanation: jerry_value_is_external() checks for external (native) objects. Question 38. What is the purpose of jerry_port_default_set_time() in the port API? A) To provide a custom random number generator. B) To set the system clock callback used by Date objects. C) To configure the debugger timestamp.
D) To initialize the garbage collector timer. Answer: B Explanation: This function registers the time‑retrieval callback required for the Date built‑in. Question 39. Which of the following is true about the “Medium” profile? A) It includes all ES5.1 features plus optional Web APIs. B) It disables RegExp and Date but keeps JSON. C) It balances size and features, typically including Date, RegExp, and JSON. D) It is identical to the “Full” profile except for the debugger. Answer: C Explanation: The Medium profile provides a middle ground, keeping common built‑ins while staying modest in size. Question 40. Which API call would you use to retrieve the length of a JavaScript string value? A) jerry_string_length(val) B) jerry_string_size(val) C) jerry_string_get_length(val) D) jerry_length_of_string(val) Answer: A Explanation: jerry_string_length() returns the number of UTF‑8 bytes in the string. Question 41. When a native function throws an exception, which return value indicates the exception to the engine? A) jerry_create_error(...) B) jerry_throw_error(...)
C) jerry_error_reference(message) D) jerry_new_error(JERRY_ERROR_REFERENCE, message) Answer: B Explanation: The generic jerry_create_error() takes an error type enum. Question 45. Which of the following correctly checks for a pending JavaScript exception after calling a native API? A) if (jerry_is_exception()) … B) if (jerry_value_is_exception(result)) … C) if (jerry_has_exception()) … D) if (jerry_exception_pending()) … Answer: B Explanation: jerry_value_is_exception() tests whether a returned value is an exception. Question 46. What does the function jerry_port_default_set_log() configure? A) The default console.log implementation. B) A custom logging callback for internal engine messages. C) The output of the debugger protocol. D) The error handling routine. Answer: B Explanation: It registers a host‑provided log function used by the engine for diagnostics. Question 47. Which of the following statements about snapshots is FALSE? A) Snapshots can be loaded without any parsing step. B) They are platform‑independent bytecode images.
C) Snapshots reduce RAM usage at runtime. D) Snapshots must be generated on the target device. Answer: D Explanation: Snapshots are typically generated on a host machine and then transferred to the device. Question 48. Which macro enables the ECMA‑262 regular expression engine? A) JERRY_ENABLE_REGEXP= B) JERRY_REGEXP_SUPPORT=ON C) JERRY_ENABLE_REGEXP_BUILTIN= D) JERRY_REGEXP_BUILTIN=TRUE Answer: C Explanation: The specific macro controlling RegExp is JERRY_ENABLE_REGEXP_BUILTIN. Question 49. Which of the following is the correct way to retrieve a property named “foo” from a JavaScript object? A) jerry_get_property(obj, jerry_create_string("foo")) B) jerry_object_get(obj, "foo") C) jerry_get_prop(obj, "foo") D) jerry_property_get(obj, jerry_string("foo")) Answer: A Explanation: Property keys must be JavaScript strings; jerry_create_string() creates the key. Question 50. How does JerryScript handle JavaScript Symbol values? A) Symbols are not supported at all.
Answer: D Explanation: There is no NETWORK error type in the standard enumeration. Question 54. When creating a native function, which return type must the handler have? A) void* B) jerry_value_t C) int D) bool Answer: B Explanation: Native handlers return a jerry_value_t that becomes the JavaScript function’s return value. Question 55. Which API call retrieves the global object of the current JerryScript context? A) jerry_get_global_object() B) jerry_global_object() C) jerry_get_this() D) jerry_get_root_object() Answer: A Explanation: jerry_get_global_object() returns a reference to the global scope. Question 56. In the port layer, which function must be provided to allocate memory for the engine? A) jerry_port_default_set_malloc()
B) jerry_port_memory_alloc() C) jerry_port_default_set_heap() D) jerry_port_default_set_mem_alloc() Answer: A Explanation: The default port can be overridden with custom malloc/free via jerry_port_default_set_malloc(). Question 57. Which of the following best describes the “mark” phase of JerryScript’s GC? A) It frees all objects immediately. B) It traverses reachable objects and marks them as live. C) It compacts memory to eliminate fragmentation. D) It converts objects to a compressed format. Answer: B Explanation: The mark phase identifies reachable objects; the sweep phase later frees the unmarked ones. Question 58. Which function can be used to retrieve the current size of the JerryScript heap in bytes? A) jerry_heap_get_size() B) jerry_get_memory_stats(&stats) and read stats.heap_size C) jerry_memory_usage() D) jerry_heap_current_size() Answer: B Explanation: jerry_get_memory_stats() fills a struct containing heap_size among other fields. Question 59. Which of the following is true about the “Full” profile?