In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the answers to JavaScript interview questions". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
What's the difference between 1:Java and JavaScript?
JavaJavaScript
Java is an OOP programming language. JavaScript is an OOP scripting language. It creates applications that run in a virtual machine or browser. The code runs on a browser or node environment. The Java code needs to be compiled. JS code is all in the form of text.
Question 2: what Javascript
JavaScript is a lightweight interpretive programming language with object-oriented features that allows you to build interactivity in other static HTML pages. The common core of the language is embedded in Netscape,Internet Explorer and other Web browsers.
Question 3: which data types are supported by JS
Data types supported by JS:
● Undefined
● Null
● Boolean
● String
● Symbol
● Number
● Object
What are the characteristics of 4:JavaScript?
The following are the features of JS:
● JS is a lightweight, interpretive programming language.
● is designed to create network-centric applications.
● complements and integrates Java
● complements and integrates HTML
● is open and cross-platform
Problem 5:JavaScript is case sensitive
Yes, JS is a case-sensitive language. Keywords, variables, function names, and any other identifiers must always be used in consistent uppercase letters.
What are the advantages of 6:JS?
The following advantages of using JS:
● less server interaction-user input can be validated before the page is sent to the server, saving server traffic, which means less load on the server
● immediate feedback-users don't have to wait for the page to reload to see if they forgot to type something.
● enhanced interaction-in the interface, users respond when they hover with the mouse or activate them through the keyboard.
● rich interface-you can use JS to include items such as drag-and-drop components and sliders to provide a rich interface for your website.
Question 7: how to create objects with JS
JS thieves support the concept of objects, which can be created in the following ways:
Var emp = {name: "Daniel", age: 23}
Question 8: how to create an array with JS
JS also makes it easy to create an array:
Var x = []; var y = [1,2,3,4,5]
What is the named function in the question 9:JS and how is it defined:
Named functions declare names immediately after definition, which can be defined using the function keyword:
Function named () {/ / write code here}
Question 10: can you assign an anonymous function to a variable and pass it as an argument to another function
Sure. An anonymous function can be assigned to a variable, or it can be passed as an argument to another function.
What is the parameter object in the question 11:JS & how to obtain the parameter type passed to the function
The JS variable arguments represents the parameters passed to the function. Using the typeof operator, you can get the type of parameter passed to the function. As follows:
Function func (x) {console.log (typeof x, arguments.length);} func (); / / = = > "undefined", 0func (7); / / = > "number", 1func ("1", "2", "3"); / / = > "string", 3
What is the scope of variables in question 12:JS
The scope of a variable is the area in the program that defines it, and the JS variable has only two scopes:
● global variable-the global variable has a global scope, which means that it is visible anywhere in the JS code.
● local variable-the local variable is only visible in the function in which it is defined, and the function argument is always the local parameter of the function.
What is the purpose of the "this" operator in question 13:JS?
The this keyword refers to the object to which it belongs. It has different values depending on where it is used. In the method, this refers to the owner object, while in the function, this refers to the global object.
Question 14: what is a callback
A callback function is a normal JS function that is passed to a method as an argument or option. It is a function that executes after another function finishes execution, so it is called a callback. In JS, a function is an object, so a function can take a function as an argument and can be returned by other functions.
Question 15: what is a closure? For instance
A closure is created whenever a variable defined outside the current scope is accessed within an internal scope. It allows you to access the scope of an external function from an internal function. In JS, closures are created each time a function is created. To use closures, simply define a function in another function and expose it.
Question 16: list some built-in methods and the values they return.
The built-in method returns a value
CharAt (), which returns the character at the specified index. Concat () it concatenates two or more strings. ForEach (), which calls a function for each element in the array. IndexOf (), which returns the index in the string object when the specified value occurs for the first time. Pop () it removes the last element from the array and returns it. Push () it adds one or more elements to the end of the array and returns the new length of the array. Reverse () reverses the order of the array elements.
Question 17: what is the variable naming convention in JS?
Follow these rules when naming variables in JS:
We should not use any JS reserved keywords as variable names. For example,
Break
Or
Boolean
The variable name is invalid. JS variable names should not be numeric
(0-9)
The beginning. They must begin with a letter or underscore. For example,
123name
Is an invalid variable name, but
123name
Or
Name123
Is a valid variable name. JS variable names are case sensitive. For example,
Test
And
Test
Are two different variables.
Question how the 18:TypeOf operator works
The data type whose Operand is used by the typeof operator. Operands can be literals or data structures, such as variables, functions, or objects. It is a unary operator that precedes its single Operand and can be of any type. Its value is a string that represents the data type of the Operand.
Question 19: how to create a cookie using JS
The easiest way to create a cookie is to assign a string value to the [xss_clean] object, as follows:
[xss_clean] = "key1 = value1; key2 = value2; expires = date"
Question 20: how to use JS to read cookie
Reading cookie is as simple as writing to cookie, because the value of the [xss_clean] object is cookie.
The value of ● [xss_clean] is a list of name=value pairs separated by semicolons, where name is the name of the cookie and value is its string value.
● can use the split () method to decompose a string into keys and values.
Question 21: how to use JS to delete cookie
If you want to delete the cookie in order to later try to read the cookie, simply set the expiration date to the time in the past. We should define the cookie path to ensure that the correct cookie is deleted. If no path is specified, some browsers will not allow us to delete cookie.
What's the difference between 22:Attribute and Property?
● Attribute-- provides more details about the element, such as id, type, value, and so on.
● Property-the value assigned to the attribute, such as type = "text", value = 'Name', and so on.
Question 23: list the different ways to access HTML elements in JS code
The following is a list of methods for accessing html elements in JS code:
● getElementById ('idname'): get elements by id name
● getElementsByClass ('classname'): gets all elements with a given class name
● getElementsByTagName ('tagname'): gets all elements with a given tag name
● querySelector (): this function takes the css style selector and returns the first selected element
How can the problem 24:JS code be used in the HTML file
There are three main types:
● inline
● internal
External to ●
In-line mode:
...
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.