JS Questions:Front-end Developer Interview Questions

简介: Explain event delegationEvent delegation allows us to attach a single event listener, to a parent element, that will fire for all children matching ...

Explain event delegation

Event delegation allows us to attach a single event listener, to a parent element, that will fire for all children matching a selector, whether those children exist now or are added in the future.the underlying cause is browser's event bubbling ;

Explain how this works in JavaScript

The this object is bound at runtime based on the context in which a function is executed:

  • when used inside global functions,this is equal to window in nostrict mode and undefined in strict mode.
  • whereas this is equal to the object when called as an object method.
  • as a constructor
  • call and apply
  • bound functions
  • as dom event handler

Explain how prototypal inheritance works

Whenever a function is created, its prototype property is also created according to a specific set of rules.
When it comes to inheritance, JavaScript only has one construct: objects. Each object has an internal link to another object called its prototype. That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype. null, by definition, has no prototype, and acts as the final link in this prototype chain.

How do you go about testing your JavaScript?

Grunt/Karma + Jasmine/QUnit

AMD vs. CommonJS?

What's a hashtable?

Hashtable is a data structure that associates keys with values;

Explain why the following doesn't work as an IIFE: function foo(){ }();.

What needs to be changed to properly make it an IIFE?

The most widely accepted way to tell the parser to expect a function expression is just to wrap in in parens, because in JavaScript, parens can’t contain statements. At this point, when the parser encounters the function keyword, it knows to parse it as a function expression and not a function declaration.

What's the difference between a variable that is: null, undefined or undeclared?

How would you go about checking for any of these states?

the undefined variable is a declared but has a value of undefined. To use a undeclared variable will cause an error.

What is a closure, and how/why would you use one?

Closures are functions that have access to variables from anthor function's scope.
This is often accomplished by creating a function inside a function.

What's a typical use case for anonymous functions?

  • event handler
  • IIFE

Explain the "JavaScript module pattern" and when you'd use it.

Bonus points for mentioning clean namespacing.

What if your modules are namespace-less?

The module pattern use a anonymous function that returns a object.
Inside of the anonymous function, the private variables and functions are defined first.
After that, an object literal is returned as the function value. That object literal contains only properties and methods that should be public. Since the object is defined inside the anonymous function, all of the public methods have access to the private variables and functions.

How do you organize your code? (module pattern, classical inheritance?)

I developing SPA with requirejs and MVC Framework recently. So I organize my code with AMD.

What's the difference between host objects and native objects?

  • Native objects are those objects supplied by JavaScript. Examples of these are String, Number, Array, Image, Date, Math, etc.

  • Host objects are objects that are supplied to JavaScript by the browser environment. Examples of these are window, document, forms, etc.

Difference between:

function Person(){} 
var person = Person() 
var person = new Person()

var-functionname-function-vs-function-functionname

What's the difference between .call and .apply?

These methods both call the function with a specific this value. * the apply() method accepts two arguments: the value of this and an array of arguments. * the call() method exhibits the same behavior as apply(),but arguments are passed to it differently.Using call() arguments must be enumerated specifically.

explain Function.prototype.bind?

ECMAScript 5 defines an addition method called 'bind()'.the 'bind()' method create a new function instance whose this value is bound to the value to that was passed into 'bind()'.

When do you optimize your code?

For release, we will compress and combine code.
Whenever I have a time I will review my code and refactor it.

Can you explain how inheritance works in JavaScript?

When would you use document.write()?

Most generated ads still utilize document.write() although its use is frowned upon

Use less as far as possible

What's the difference between feature detection, feature inference, and using the UA string

  • Feature Detection is to identify the browser's capabilities.
  • Feature Inference is guess whether browser has certain feature through others feature or UA string.
    • One inappropriate use of feature detection is called feature inference. Feature inference attempts to use multiple features after validating the presence of only one. The presence of one feature is inferred by the presence of another. The problem is, of course, that inference is an assumption rather than a fact, and that can lead to maintenance issues.
  • UA String is User-Agent Detection.

Explain AJAX in as much detail as possible

AJAX is short for Asynchronous Javascript + XML. The technique consisted of making server requests for additional data without unloading the page,resulting in a better user experience.

Explain how JSONP works (and how it's not really AJAX)

Have you ever used JavaScript templating?

If so, what libraries have you used? (Mustache.js, Handlebars etc.)

  • Handlebars
  • _.tmpl
  • $.tmpl

Explain "hoisting".

There is a preproccess or precompile in javascript runtime. and 'Hoisting' occur in the preproccess.

Function declarations and variable declarations are always moved (“hoisted”) invisibly to the top of their containing scope by the JavaScript interpreter. This means that code like this:

function foo() {
    bar();
    var x = 1;
}

is actually interpreted like this:

function foo() {
    var x;
    bar();
    x = 1;
}

JavaScript-Scoping-and-Hoisting

Describe event bubbling.

Event Flow describles the order in which events are received on the page.An event has three phases to its life cycle: capture, target, and bubbling.
Event Bubbling mean that an event start at the most specific element(the deepest possible point to the document tree) and then flow upward toward the least specific node(the document);

What's the difference between an "attribute" and a "property"?

Often an attribute is used to describe the mechanism or real-world thing.

A property is used to describe the model.

In HTML / Javascript the terms get confused because DOM Elements have attributes (per the HTML source) which are backed by properties when those elements are represented as Javascript objects.

To further confuse things, changes to the properties can sometimes update the attributes.

For example, changing the element.href property will update the href attribute on the element, and that'll be reflected in a call to element.getAttribute('href').

However if you subsequently read that property, it will have been normalised to an absolute URL, even though the attribute might be a relative URL!

Why is extending built in JavaScript objects not a good idea?

Depend on the way of extending.

Why is extending built ins a good idea?

Depend on the way of extending.

Difference between document load event and document ready event?

  • ready means DOM is ready.
  • load means the page fully loaded. Includes inner frames, images etc.

What is the difference between == and ===?

The == operator will compare for equality after doing any necessary type conversions. The === operator will not do the conversion, so if two values are not the same type === will simply return false. It's this case where === will be faster, and may return a different result than ==. In all other cases performance will be the same.

Explain how you would get a query string parameter from the browser window's URL.

1.var queryString = location.search 2.parse queryString * queryString.split("=") * regExp 3.return specific parameter.

Explain the same-origin policy with regards to JavaScript.

Describe inheritance patterns in JavaScript.

  • Make this work: javascript [1,2,3,4,5].duplicate(); // [1,2,3,4,5,1,2,3,4,5]

    Describe a strategy for memoization (avoiding calculation repetition) in JavaScript.

Why is it called a Ternary expression, what does the word "Ternary" indicate?

What is the arity of a function?

What is "use strict";?

what are the advantages and disadvantages to using it?

相关文章
|
13天前
|
人工智能 JSON 机器人
让龙虾成为你的“公众号分身” | 阿里云服务器玩Openclaw
本文带你零成本玩转OpenClaw:学生认证白嫖6个月阿里云服务器,手把手配置飞书机器人、接入免费/高性价比AI模型(NVIDIA/通义),并打造微信公众号“全自动分身”——实时抓热榜、AI选题拆解、一键发布草稿,5分钟完成热点→文章全流程!
11455 124
让龙虾成为你的“公众号分身” | 阿里云服务器玩Openclaw
|
2天前
|
人工智能 JSON 监控
Claude Code 源码泄露:一份价值亿元的 AI 工程公开课
我以为顶级 AI 产品的护城河是模型。读完这 51.2 万行泄露的源码,我发现自己错了。
3470 8
|
1天前
|
人工智能 数据可视化 安全
王炸组合!阿里云 OpenClaw X 飞书 CLI,开启 Agent 基建狂潮!(附带免费使用6个月服务器)
本文详解如何用阿里云Lighthouse一键部署OpenClaw,结合飞书CLI等工具,让AI真正“动手”——自动群发、生成科研日报、整理知识库。核心理念:未来软件应为AI而生,CLI即AI的“手脚”,实现高效、安全、可控的智能自动化。
1333 2
王炸组合!阿里云 OpenClaw X 飞书 CLI,开启 Agent 基建狂潮!(附带免费使用6个月服务器)
|
12天前
|
人工智能 IDE API
2026年国内 Codex 安装教程和使用教程:GPT-5.4 完整指南
Codex已进化为AI编程智能体,不仅能补全代码,更能理解项目、自动重构、执行任务。本文详解国内安装、GPT-5.4接入、cc-switch中转配置及实战开发流程,助你从零掌握“描述需求→AI实现”的新一代工程范式。(239字)
7467 139
|
2天前
|
云安全 供应链 安全
Axios投毒事件:阿里云安全复盘分析与关键防护建议
阿里云云安全中心和云防火墙第一时间响应
1144 0
|
3天前
|
人工智能 自然语言处理 数据挖掘
零基础30分钟搞定 Claude Code,这一步90%的人直接跳过了
本文直击Claude Code使用痛点,提供零基础30分钟上手指南:强调必须配置“工作上下文”(about-me.md+anti-ai-style.md)、采用Cowork/Code模式、建立标准文件结构、用提问式提示词驱动AI理解→规划→执行。附可复制模板与真实项目启动法,助你将Claude从聊天工具升级为高效执行系统。
|
2天前
|
人工智能 定位技术
Claude Code源码泄露:8大隐藏功能曝光
2026年3月,Anthropic因配置失误致Claude Code超51万行源码泄露,意外促成“被动开源”。代码中藏有8大未发布功能,揭示其向“超级智能体”演进的完整蓝图,引发AI编程领域震动。(239字)
2152 9
|
11天前
|
人工智能 并行计算 Linux
本地私有化AI助手搭建指南:Ollama+Qwen3.5-27B+OpenClaw阿里云/本地部署流程
本文提供的全流程方案,从Ollama安装、Qwen3.5-27B部署,到OpenClaw全平台安装与模型对接,再到RTX 4090专属优化,覆盖了搭建过程的每一个关键环节,所有代码命令可直接复制执行。使用过程中,建议优先使用本地模型保障隐私,按需切换云端模型补充功能,同时注重显卡温度与显存占用监控,确保系统稳定运行。
2555 9