avatar
Articles
29
Tags
1
Categories
0
Home
Archives
Huck's dev blog
Search
Home
Archives

Huck's dev blog

protoType and protoType Chain
Created2024-11-16
there is simple question how can you check if a variable is an Array。the answer is easy 1arr instanceof Array if result is true ,arr is Array .otherwise arr isn’t; so there is another question: what’s principle behind instanceof in Javascript let me explain there’re two classes. People and Student . Student implements People 123456789101112131415161718class People{ constructor(name){ this.name = name } eat(){ console.log(`${this.name}...
When to Use === and ==
Created2024-11-13
Use the == operator only when checking for null or undefined. In all other cases, use === for strict equality.For example: 12if(obj.a == null){} is equivalent to: 12if (obj.a === null || obj.a === undefined) {}
Implement deepClone manually
Created2024-11-13
Reason:Reference types will share the same address, so when we use = operator, if there is modification on the new object, the value on the old object will change too. SolutionIterate the Object recursively. If there is reference type, we create a new one and copy all the value type to the new reference type. 12345678910111213141516171819202122232425262728function deepClone(obj = {}) { // null can't be treated as object if (typeof obj != "object"...
decode message
Created2024-03-26
There is a interview question on bfe.dev about decode-message. The link is below https://bigfrontend.dev/problem/decode-message Your are given a 2-D array of characters. There is a hidden message in it. 123I B C A L K AD R F C A E AG H O E L A D col and row are marked with number which start from 0. The number of col is 0 ~ 6 ,and the number of row is 0~2The way to collect the message is as follows start at top left move diagonally down right when cannot move any more, try to switch to...
Implementing the apply Function Manually
Created2024-02-26
Steps to implement the apply function: Determine if the calling object is a function. Even though it’s defined on the function’s prototype, there may be instances where it is invoked using methods like call. Check if the incoming context object exists; if not, set it to window. Assign the function as a property of the context object. Determine if the parameter values have been passed in. Invoke the method using the context object and save the returned result. Remove the property that...
Flatten the array
Created2024-02-05
(1) Recursive implementationThe common idea behind recursion is straightforward, involving a circular recursion approach where each item is iterated over. If an item is still an array, the process continues recursively to achieve the concatenation of each array item. 1234567891011121314let arr = [1, [2, [3, 4, 5]]];function flatten(arr) { let result = []; for(let i = 0; i < arr.length; i++) { if(Array.isArray(arr[i])) { result = result.concat(flatten(arr[i]));...
Implement deep copy
Created2024-02-05
○ Shallow copy: Shallow copy refers to copying the attribute value of one object to another object. If the attribute value is a reference type, then the address of the reference is copied to the object, so the two objects will have a reference of the same reference type. Shallow copying can be implemented using Object.assign() and the spread operator. ○ Deep copy: Compared to shallow copy, if a property value is a reference type, deep copy creates a reference type and copies the...
What is the purpose of the newly added primitive data type "Symbol"?
Created2024-01-28
Discuss conceptual questions‘Symbol’ is a primitive data type introduced in ES6. Its primary purpose is to create a unique identifier, which is used in scenarios such as naming object properties, defining constants, and so on. Understanding with Examples Each ‘Symbol’ is unique and can be used as a property name for objects, which helps to avoid conflicts with property names. For example: 1234567const s1 = Symbol();const s2 = Symbol();const obj = { [s1]: 'hello', [s2]:...
What are the differences in asynchronous loading of JS scripts?
Created2024-01-28
What are the differences in asynchronous loading of JS scripts?In Web applications, the asynchronous loading of JavaScript scripts can be achieved in the following ways: a. Dynamically create a tag and set its src attribute to the URL of the script to be loaded. You can use the onload or onreadystatechange event to check if the script has finished loading. 123456const script = document.createElement('script');script.src = 'path/to/script.js';script.onload = function()...
Why is the result of 'typeof null' an 'object'?
Created2024-01-21
Why is the result of ‘typeof null’ an ‘object’?KernelThe result of ‘typeof null’ being “object” is a legacy issue of the JavaScript language. In the original version of JavaScript, a 32-bit value was used to represent a variable, with the first 3 bits representing the type of the value. 000 represents an object, 010 represents a floating point number, 100 represents a string, 110 represents a Boolean value, and other values are all considered pointers. In this representation, null was...
123
avatar
huck@love
Articles
29
Tags
1
Categories
0
Follow Me
Announcement
This is my Blog
Recent Posts
Secure Skill Installation in Codex2026-04-08
Claude.md The Longer, The Worse ?2026-02-14
Single-Sided Liquidity2025-07-07
SSE chat bot2025-07-06
enable CORS support in Chrome on Mac2025-05-02
Tags
CORS, Chrome, macOS, Web Development
Archives
  • April 2026 1
  • February 2026 1
  • July 2025 2
  • May 2025 1
  • February 2025 1
  • January 2025 3
  • November 2024 4
  • March 2024 1
Website Info
Article Count :
29
Unique Visitors :
Page Views :
Last Update :
©2019 - 2026 By huck@love
Framework Hexo|Theme Butterfly
Search
Loading Database