What are the possible ways to create objects in JavaScript Possible ways to create objects in JavaScript include object literals ({}), the new Object() constructor, constructor functions, ES6 classes, and Object.create(). What is a prototype chain The prototype chain is a mechanism in JavaScript where objects inherit properties and methods from other objects, forming a chain that is traversed when a property is accessed. What is the Difference Between call, apply, and bind call and apply execute a function immediately, setting the this value, with call taking arguments individually and apply taking arguments as an array; bind returns a new function with the this value permanently set. What is JSON and its common operations JSON (JavaScript Object Notation) is a lightweight data-interchange format, and its common operations include parsing (JSON.parse()) to convert a JSON string to a JavaScript object and stringifying (JSON.stringify()) to convert a JavaScript object to a JSON string. What is the purpose of the array slice method The array slice() method returns a shallow copy of a portion of an array into a new array object, selecting elements from a start to an end index (not inclusive), without modifying the original array. What is the purpose of the array splice method The array splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place, and it returns the removed elements. What is the difference between slice and splice slice() returns a new array containing a copy of a portion of the original array and does not modify the original, while splice() modifies the original array by adding, removing, or replacing elements. How do you compare Object and Map An Object is the most basic building block, where keys must be strings or Symbols, and it doesn't maintain insertion order; a Map is a collection of keyed data items where keys can be of any data type, and it maintains insertion order. What is the difference between == and === operators The == (equality) operator compares values, performing type coercion if the operands are of different types; the === (strict equality) operator compares values and checks if the operands are of the same type, with no type coercion. What are lambda expressions or arrow functions Lambda expressions or arrow functions (=>) provide a concise syntax for writing functions and do not have their own this, arguments, super, or new.target bindings. What is a first class function A first-class function means that functions in that language are treated like any other variable: they can be assigned to variables, passed as arguments to other functions, and returned as values from other functions. What is a first order function A first-order function is a function that does not take another function as an argument and does not return a function. What is a higher order function A higher-order function is a function that either takes one or more functions as arguments or returns a function as its result. What is a unary function A unary function (or monad) is a function that accepts exactly one argument. What is the currying function Currying is a functional programming technique of transforming a function that takes multiple arguments into a sequence of functions, each taking a single argument. What is a pure function A pure function is a function that, given the same input, will always return the same output and has no side effects (it does not modify anything outside its scope). What are the benefits of pure functions Benefits of pure functions include predictability (easier to test and reason about), referential transparency (can replace function call with its result), and they enable caching/memoization. What is the purpose of the let keyword The let keyword is used to declare block-scoped local variables, meaning the variable is only accessible within the block of code where it is defined. What is the difference between let and var let declares variables that are block-scoped and cannot be redeclared within the same scope, whereas var declares variables that are function-scoped (or global) and can be redeclared. What is the reason to choose the name let as a keyword The name let was chosen to indicate that it provides a way to declare a lexically-scoped variable, similar to how it's used in mathematical assertions and other programming languages. How do you redeclare variables in a switch block without an error You can redeclare variables inside a switch block without an error by wrapping the case block contents in curly braces ({}), which creates a new block scope for the variable declaration. What is the Temporal Dead Zone The Temporal Dead Zone (TDZ) is the time span between a variable's creation by the JavaScript engine and its initialization (where it's assigned a value), during which accessing the variable (declared with let or const) will result in a ReferenceError. What is an IIFE (Immediately Invoked Function Expression) An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined, often used to create a private scope for variables and avoid polluting the global namespace. How do you decode or encode a URL in JavaScript? To decode a URL, you use decodeURI() or decodeURIComponent(); to encode a URL, you use encodeURI() or encodeURIComponent(). What is memoization Memoization is an optimization technique used primarily to speed up computer programs by caching the results of expensive function calls and returning the cached result when the same inputs occur again. What is Hoisting Hoisting is a JavaScript mechanism where variable and function declarations are moved to the top of their containing scope during the compilation phase, but only the declaration, not the assignment, is hoisted. What are classes in ES6 Classes in ES6 are primarily syntactic sugar over JavaScript's existing prototype-based inheritance model, providing a cleaner, more conventional way to create objects and deal with inheritance. What are closures Closures are a combination of a function and the lexical environment (scope) within which that function was declared, allowing the inner function to access variables from its outer function's scope even after the outer function has finished execution. What are modules Modules are self-contained pieces of code that export specific values (functions, variables, classes) and import values from other modules, helping to organize code into smaller, reusable chunks. Why do you need modules You need modules to achieve better code organization, prevent global scope pollution, and facilitate code reuse and dependency management. What is scope in javascript Scope in JavaScript refers to the accessibility of variables, functions, and objects in some particular part of your code; it determines where you can access a variable. What is a service worker A Service Worker is a type of web worker that acts as a proxy between the web browser and the network, enabling features like offline support, network request interception, and push notifications. How do you manipulate DOM using a service worker You cannot manipulate the DOM directly from a Service Worker because it runs in a separate thread; manipulation must be done by sending messages to the pages it controls, which then handle the DOM updates. How do you reuse information across service worker restarts Information can be reused across Service Worker restarts by storing it persistently using browser APIs like IndexedDB or the Cache Storage API. What is IndexedDB IndexedDB is a low-level API for client-side storage of significant amounts of structured data, including files/blobs, and is an asynchronous database system. What is web storage Web Storage refers to APIs that let web applications store data locally within the user's browser, typically including localStorage and sessionStorage. What is a post message A postMessage is a method used to securely communicate between different origins, windows, or web workers in a browser, allowing for cross-origin communication. What is a Cookie A Cookie is a small piece of text data that a server sends to a user's web browser, which the browser may store and then send back with subsequent requests to the same server. Why do you need a Cookie You need a Cookie primarily for session management (logging in), personalization (user preferences), and tracking (user behavior). What are the options in a cookie Options in a cookie include Expires or Max-Age (when it expires), Domain, Path, Secure (HTTPS only), HttpOnly (prevents client-side access), and SameSite. How do you delete a cookie To delete a cookie, you must set its Expires date to a past date or set its Max-Age to 0, ensuring the Domain and Path attributes match those used when the cookie was created. What are the differences between cookie, local storage and session storage Cookies are small (max $\approx 4$ KB), sent with every HTTP request, and have an expiration date; localStorage and sessionStorage are larger ($\approx 5$-$10$ MB), client-side only, and not sent with requests. What is the main difference between localStorage and sessionStorage The main difference is that localStorage persists data even after the browser is closed (no expiration), whereas sessionStorage data is cleared when the browser tab/window is closed. How do you access web storage You access Web Storage by using the localStorage and sessionStorage objects on the window object, with methods like .setItem(key, value) and .getItem(key). What are the methods available on session storage The methods available on sessionStorage are .setItem(key, value), .getItem(key), .removeItem(key), .key(index), and .clear(). What is a storage event and its event handler A storage event fires on other browser windows/tabs from the same origin when a storage area is modified; its event handler receives a StorageEvent object with details about the change. Why do you need web storage You need Web Storage to provide client-side data persistence, allowing web applications to store user-specific data or state locally for a faster and richer user experience. How do you check web storage browser support You check Web Storage browser support by testing if the localStorage and sessionStorage properties exist on the window object: if (window.localStorage). How do you check web workers browser support You check Web Workers browser support by testing for the existence of the Worker property on the global object: if (window.Worker). Give an example of a web worker An example of a web worker involves creating a new worker with const myWorker = new Worker('worker.js'); and then communicating using postMessage() and listening with onmessage. What are the restrictions of web workers on DOM The main restriction of web workers is that they do not have direct access to the DOM (Document Object Model) of the main page, nor access to the global window, document, or parent objects. What is a promise A Promise is an object representing the eventual completion or failure of an asynchronous operation and its resulting value. Why do you need a promise You need a Promise to manage asynchronous operations in a more structured, readable, and less error-prone way than traditional callbacks, helping to avoid callback hell. Explain the three states of promise The three states of a Promise are pending (initial state), fulfilled (operation completed successfully), and rejected (operation failed). What is a callback function A callback function is a function passed as an argument to another function, which is then executed (called back) inside the outer function to complete an action. Why do we need callbacks We need callbacks to handle code execution after an asynchronous operation (like a network request or a timer) has completed, ensuring that logic runs at the correct time. What is a callback hell Callback hell (or the pyramid of doom) is a term used to describe deeply nested, hard-to-read, and difficult-to-maintain code that results from using multiple asynchronous operations executed with traditional callbacks. What are server-sent events Server-Sent Events (SSE) are a mechanism that allows a web application to efficiently receive automatic updates (pushed data) from a server over a single, long-lived HTTP connection. How do you receive server-sent event notifications You receive server-sent event notifications by creating a new EventSource object and listening for messages using the onmessage event handler. How do you check browser support for server-sent events You check browser support for server-sent events by checking for the existence of the EventSource object on the global window object: if (window.EventSource). What are the events available for server sent events The events available for server-sent events are open (connection established), message (data received), and error (connection failure or error). What are the main rules of promise] The main rules of a Promise are that it is immutable once settled (fulfilled or rejected), and it can only transition from pending to either fulfilled or rejected only once. What is callback in callback Callback in callback refers to the pattern of passing a callback function as an argument to an asynchronous function, and then, within that callback, passing *another* callback to *another* asynchronous function, leading to nesting. What is promise chaining Promise chaining is the process of linking multiple asynchronous operations together using the .then() method, where the return value of one promise becomes the input for the next one, resulting in sequential execution. What is promise.all Promise.all() takes an iterable of promises and returns a single promise that fulfills when all of the promises have fulfilled, or rejects immediately upon the first promise that rejects. What is the purpose of the race method in promise The purpose of the Promise.race() method is to take an iterable of promises and return a single promise that settles (fulfills or rejects) with the same outcome as the first promise in the iterable that settles. What is a strict mode in javascript Strict mode is a way to opt in to a restricted variant of JavaScript, which disallows certain actions and throws more exceptions, making code safer and easier to debug. Why do you need strict mode You need strict mode to eliminate some silent errors by changing them to throw errors, fix mistakes that make it difficult for JavaScript engines to perform optimizations, and prohibit confusing or dangerous syntax. How do you declare strict mode You declare strict mode by placing the string literal "use strict"; at the very beginning of a script or a function. What is the purpose of double exclamation The purpose of the double exclamation mark (!!) is to explicitly convert any value to a boolean (true or false). What is the purpose of the delete operator The purpose of the delete operator is to remove a property from an object or an element from an array. What is typeof operator The typeof operator returns a string indicating the data type of its operand (e.g., "string", "number", "object", "undefined"). What is undefined property The undefined property is a primitive value that indicates that a variable has been declared but has not been assigned a value. What is null value The null value is a primitive value that represents the intentional absence of any object value or is used to denote an empty value. What is the difference between null and undefined undefined means a variable has been declared but not assigned a value (default value), while null is a value that can be explicitly assigned to a variable to indicate the intentional absence of a value. What is eval eval() is a function that executes JavaScript code represented as a string in the current scope. What is the difference between window and document The window object represents the browser window itself and is the global object; the document object is a property of the window object and represents the DOM (HTML content) loaded within the window. How do you access history in javascript You access history in JavaScript using the history object, which is a property of the window object, and methods like history.back(), history.forward(), and history.go(n). How do you detect caps lock key turned on or not You can detect if the Caps Lock key is turned on by checking the getModifierState('CapsLock') method on the keyboard event object. What is isNaN isNaN() is a global function that determines whether a value is the special value NaN (Not-a-Number) after converting the argument to a number. What are the differences between undeclared and undefined variables Undeclared variables are those that have not been formally created and accessing them throws a ReferenceError; undefined variables are those that have been declared but not assigned a value. What are global variables Global variables are variables declared outside of any function or those declared without var, let, or const inside a function, making them accessible from anywhere in the code. What are the problems with global variables The problems with global variables include naming collisions (especially with third-party libraries), making code harder to maintain and debug, and making it difficult to use modules effectively. What is NaN property The NaN property (Not-a-Number) is a special numeric value that represents a value that is not a legal number; it is unique because NaN === NaN is false. What is the purpose of isFinite function The purpose of the isFinite() function is to determine whether a value is a finite number; it returns false if the argument is $\pm \infty$ or NaN. What is an event flow Event flow is the order in which events are processed from the top-most ancestor element down to the target element (capturing phase) and then from the target element up to the top-most ancestor (bubbling phase). What is event capturing Event capturing is the phase of the event flow where an event is first captured by the outermost ancestor element and propagates down to the target element. What is event bubbling Event bubbling is the phase of the event flow where an event propagates up from the target element to its immediate parent and subsequently up through all ancestors to the root of the document. How do you submit a form using JavaScript You submit a form using JavaScript by calling the .submit() method on the HTMLFormElement object (e.g., document.getElementById('myForm').submit()). How do you find operating system details You find operating system details by checking the navigator.platform or navigator.userAgent properties of the window.navigator object. What is the difference between document load and DOMContentLoaded events document.load (on the window) fires when the entire page has loaded, including all dependent resources; DOMContentLoaded fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets and images. What is the difference between native, host and user objects Native objects are standard, built-in JavaScript objects (like String, Date); host objects are provided by the environment (e.g., window, document in browsers); and user objects are those defined by the script writer. What are the tools or techniques used for debugging JavaScript code Tools/techniques used for debugging JavaScript code include the browser's developer tools (Sources/Debugger tab), using the console.log() method, setting breakpoints, and using the debugger statement. What are the pros and cons of promises over callbacks Promises provide a cleaner, more structured way to handle asynchronous code (pros) but can have a slightly steeper learning curve (cons) than simple callbacks. What is the difference between an attribute and a property An attribute is the initial defined property in the HTML markup; a property is the value on the DOM object in memory, which is a live value and can be changed in JavaScript. What is same-origin policy The Same-Origin Policy (SOP) is a critical security mechanism that restricts how a document or script loaded from one origin (protocol, domain, port) can interact with resources from another origin. What is the purpose of void 0 The purpose of void 0 is to explicitly get the primitive undefined value, often used to ensure the value is actually undefined or in place of undefined in older browsers. Is JavaScript a compiled or interpreted language JavaScript is primarily an interpreted language (traditionally), though modern engines use Just-In-Time (JIT) compilation. Is JavaScript a case-sensitive language Yes, JavaScript is a case-sensitive language, meaning keywords, variables, and function names must be consistently capitalized. Is there any relation between Java and JavaScript There is no relation between Java and JavaScript other than a marketing decision to name the language 'JavaScript' to capitalize on the popularity of Java at the time of its release. What are events Events are actions or occurrences that happen in the system (like a user click or a page load), which the system tells you about so you can respond to them. Who created javascript JavaScript was created by Brendan Eich while he was working at Netscape Communications in 1995. What is the use of preventDefault method The use of the preventDefault() method is to stop the browser's default action from occurring for a given event, such as preventing a form from submitting or a link from navigating. What is the use of stopPropagation method The use of the stopPropagation() method is to prevent the event from propagating further up or down the event flow (stopping either the bubbling or capturing phase). What are the steps involved in return false usage The steps involved in return false usage in an event handler are equivalent to calling both event.preventDefault() and event.stopPropagation(). What is BOM BOM (Browser Object Model) is a collection of browser-specific objects (e.g., window, navigator, screen, location) that allows JavaScript to interact with the web browser. What is the use of setTimeout The use of setTimeout() is to execute a function or a piece of code once after a specified delay (in milliseconds). What is the use of setInterval The use of setInterval() is to repeatedly execute a function or a piece of code at specified intervals (in milliseconds) until stopped by clearInterval(). Why is JavaScript treated as Single threaded JavaScript is treated as Single-threaded because it has only one call stack, meaning it can execute only one piece of code at a time in the main thread. What is an event delegation Event delegation is a pattern where you attach a single event listener to a common ancestor element, and then use event bubbling to handle events for all its descendant elements. What is ECMAScript ECMAScript is the standard that JavaScript is based on, defining the language specification; JavaScript is the most common implementation of the standard. What is JSON JSON (JavaScript Object Notation) is a lightweight, text-based data-interchange format derived from a subset of the JavaScript language. What are the syntax rules of JSON The syntax rules of JSON dictate that data is in name/value pairs separated by commas, curly braces hold objects, and square brackets hold arrays. What is the purpose JSON stringify The purpose of JSON.stringify() is to convert a JavaScript value (object, array, etc.) into a JSON string. How do you parse JSON string You parse a JSON string using the JSON.parse() method, which converts the JSON string back into a JavaScript object. Why do you need JSON You need JSON because it is a human-readable, platform-independent, and lightweight format that is widely used for data interchange (sending data between a server and a web application). What are PWAs PWAs (Progressive Web Apps) are web applications that use modern web capabilities to deliver an app-like experience to users, leveraging Service Workers for offline support. What is the purpose of clearTimeout method The purpose of the clearTimeout() method is to cancel a timeout previously established by a call to setTimeout(), preventing the function from executing. What is the purpose of clearInterval method The purpose of the clearInterval() method is to cancel an interval previously established by a call to setInterval(), stopping the repeated execution of the function. How do you redirect new page in javascript You redirect to a new page in JavaScript by setting the window.location.href property to the new URL (e.g., window.location.href = 'new-page.html';). How do you check whether a string contains a substring You check whether a string contains a substring using the .includes() method (ES6+), the .indexOf() method (returns $-1$ if not found), or a Regular Expression with the .test() method. How do you validate an email in javascript You validate an email in JavaScript most commonly by using a Regular Expression to check if the string matches the typical email format structure. How do you get the current url with javascript You get the current URL with JavaScript by accessing the window.location.href property. What are the various url properties of location object The various URL properties of the location object include href (full URL), protocol, host, pathname, search (query string), and hash (fragment). How do get query string values in javascript You get query string values in JavaScript by accessing the window.location.search property and then either manually parsing the string or using the URLSearchParams API. How do you check if a key exists in an object You check if a key exists in an object using the in operator, the .hasOwnProperty() method, or by checking if Object.keys(obj).includes(key). How do you loop through or enumerate javascript object You loop through or enumerate a JavaScript object using a for...in loop (enumerates enumerable properties) or by iterating over the results of Object.keys(), Object.values(), or Object.entries(). How do you test for an empty object You test for an empty object by checking if the array returned by Object.keys(obj) has a length of 0 (e.g., Object.keys(obj).length === 0). What is an arguments object The arguments object is an array-like object accessible inside functions that contains the values of the arguments passed to that function. How do you make first letter of the string in an uppercase You make the first letter of the string uppercase by taking the first character using .charAt(0) and converting it to uppercase with .toUpperCase(), then concatenating it with the rest of the string using .slice(1). What are the pros and cons of for loops The for loop is fast and versatile (pros) but can be verbose and less expressive for iterating over data structures than methods like forEach or map (cons). How do you display the current date in javascript You display the current date in JavaScript by creating a new Date object (new Date()) and then using methods like .toLocaleDateString() or .toString(). How do you compare two date objects You compare two date objects by converting them to their numeric timestamp values using .getTime() and then comparing the numbers. How do you check if a string starts with another string You check if a string starts with another string using the .startsWith() method (ES6+) or by checking if the result of .indexOf(substring) is 0. How do you trim a string in javascript You trim a string in JavaScript using the .trim() method, which removes whitespace from both ends of a string. How do you add a key value pair in javascript You add a key-value pair to a JavaScript object by using dot notation (obj.key = value) or bracket notation (obj['key'] = value). Is the !-- notation represents a special operator The !-- notation is not a special operator; it’s a combination of the logical NOT (!) and decrement (--) operators, often used together in specific contexts. How do you assign default values to variables Default values can be assigned using the = operator in function parameters (e.g., function foo(a = 10)) or with the logical OR (||) or nullish coalescing (??) operators for variables. How do you define multiline strings Multiline strings are defined using template literals with backticks ( ), allowing line breaks within the string, or by concatenating strings with \n. What is an app shell model The app shell model is a design pattern for progressive web apps, where a minimal HTML, CSS, and JS structure is cached to ensure fast loading and offline functionality. Can we define properties for functions Yes, functions are objects in JavaScript, so you can define properties on them using dot notation (e.g., func.prop = value). What is the way to find the number of parameters expected by a function Use the function.length property to get the number of parameters a function expects. What is a polyfill A polyfill is a piece of code that provides modern functionality for older browsers that lack native support. What are break and continue statements break exits a loop or switch statement, while continue skips the current iteration and proceeds to the next one. What are js labels Labels are identifiers followed by a colon (e.g., label:) used to mark a statement, allowing break or continue to target specific loops. What are the benefits of keeping declarations at the top Keeping declarations at the top improves code readability, avoids hoisting-related errors, and ensures variables are defined before use. What are the benefits of initializing variables Initializing variables prevents undefined errors, improves code clarity, and ensures predictable behavior. What are the recommendations to create new object Use object literals ({}), Object.create(), or classes for clear, maintainable object creation, avoiding new Object(). How do you define JSON arrays JSON arrays are defined as comma-separated values enclosed in square brackets, e.g., [1, "text", { "key": "value" }]. How do you generate random integers Use Math.floor(Math.random() * max) to generate random integers between 0 and max - 1. Can you write a random integers function to print integers within a range javascript function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } What is tree shaking Tree shaking is a bundling technique that eliminates unused code from the final JavaScript bundle to optimize performance. What is the need of tree shaking Tree shaking reduces bundle size, improves load times, and enhances application performance by removing dead code. Is it recommended to use eval Using eval is not recommended due to security risks, performance issues, and difficulty in debugging. What is a Regular Expression A Regular Expression (regex) is a pattern used to match and manipulate strings based on specific rules. What are the string methods that accept Regular expression String methods like match(), replace(), search(), and split() accept regular expressions. What are modifiers in regular expression Modifiers like (case-insensitive), (global), and (multiline) alter regex behavior. What are regular expression patterns Regex patterns are sequences of characters defining a search pattern, using literals, metacharacters, and quantifiers. What is a RegExp object A RegExp object is a JavaScript object for creating and managing regular expressions to match patterns in strings. How do you search a string for a pattern Use string.search(regex) to find the index of the first match or regex.test(string) to check if a pattern exists. What is the purpose of exec method The exec() method tests for matches in a string and returns an array with match details or null. How do you change the style of a HTML element Modify an element’s style using element.style.property = "value" (e.g., element.style.color = "blue"). What would be the result of 1+2+'3' The result is "33", as numbers are coerced to strings when concatenated with a string. What is a debugger statement The debugger statement pauses code execution, invoking the browser’s debugging tool if available. What is the purpose of breakpoints in debugging Breakpoints pause code execution at specific lines, allowing developers to inspect variables and control flow. Can I use reserved words as identifiers Reserved words cannot be used as identifiers in strict mode; in non-strict mode, it’s possible but not recommended. How do you detect a mobile browser Check the navigator.userAgent string with a regex like /Mobi|Android/i to detect mobile browsers. How do you detect a mobile browser without regexp Check for specific substrings in navigator.userAgent (e.g., userAgent.includes("Mobile")). How do you get the image width and height using JS Use image.width and image.height properties or naturalWidth and naturalHeight for original dimensions. How do you make synchronous HTTP request Use XMLHttpRequest with open("GET", url, false) for synchronous requests, though it’s discouraged. How do you make asynchronous HTTP request Use fetch() or XMLHttpRequest with async: true to make asynchronous HTTP requests. How do you convert date to another timezone in javascript Use toLocaleString() with the timeZone option (e.g., date.toLocaleString("en-US", { timeZone: "America/New_York" })). What are the properties used to get size of window Use window.innerWidth and window.innerHeight for viewport size, or screen.width and screen.height for screen size. What is a conditional operator in javascript The conditional (ternary) operator (condition ? expr1 : expr2) evaluates a condition and returns one of two expressions. Can you apply chaining on conditional operator Yes, ternary operators can be nested for chaining (e.g., condition1 ? expr1 : condition2 ? expr2 : expr3). What are the ways to execute javascript after a page load Use window.onload, DOMContentLoaded event, or defer/async script attributes to run JavaScript after page load. What is the difference between proto and prototype __proto__ is an object’s prototype reference, while prototype is a property of constructor functions for inheritance. Can you give an example of when you really need a semicolon Semicolons are needed when two statements are on the same line or to prevent ASI issues, e.g., let x = 1; [1,2].forEach(). What is the freeze method Object.freeze() makes an object immutable, preventing property additions, deletions, or modifications. What is the purpose of the freeze method The freeze method ensures an object’s state cannot be changed, useful for constants or secure data. Why do I need to use the freeze method Use Object.freeze() to protect critical data from unintended changes or ensure immutability in functional programming. How do you detect a browser language preference Check navigator.language or navigator.languages to get the browser’s preferred language. How to convert a string to title case with javascript Split the string, capitalize each word’s first letter, and join: str.toLowerCase().replace(/(^|\s)\w/g, c => c.toUpperCase()). How do you detect if javascript is disabled on the page Use a