Answer the question
In order to leave comments, you need to log in
What does .chance mean?
const express = require('express')
const app = express()
app.use((request, response, next) => { //Промежуточный обработчик
console.log(request.headers)
next()
})
app.use((request, response, next) => {
request.chance = Math.random()
next()
})
app.get('/', (request, response) => {
response.json({
chance: request.chance
})
})
app.listen(3000)
Answer the question
In order to leave comments, you need to log in
chance
is a new invented property of the object request
assigned to it by the handler.
A request has arrived. A new property chance
was attached to it, writing a random number from 0 to 1 into it.
In response to a GET request, JSON is returned describing an object with a single property, also called "chance" (chance), with a value taken from the previously assigned property of the request object.
You can name the property whatever you like. For example, toster
. Then the code would look like this (replacement in two places), but function exactly the same; returned the same response format:
const express = require('express')
const app = express()
app.use((request, response, next) => { //Промежуточный обработчик
console.log(request.headers)
next()
})
app.use((request, response, next) => {
request.toster = Math.random()
next()
})
app.get('/', (request, response) => {
response.json({
chance: request.toster
})
})
app.listen(3000)
.headers
is a property of the request object inherited from the native Node request object, see http.IncomingMessage.headers . Contains all HTTP headers of the received HTTP request.
Judging by the code, it looks like some kind of game system, where .chance gets a random chance, and all other chances seem to be recalculated below. Huh, probably not right.
Only one thing came to mind - https://coub.com/view/7fzfq
Look at the code where this value is used. If not, you can delete it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question