console.log

What is the difference between , and + in the console.log?

拟墨画扇 提交于 2021-02-20 04:32:55
问题 pt=new Date(2019,11,12,8,2,3) console.log(pt.getFullYear()," ",pt.getMonth()); gives result 2019 " " 11 console.log(pt.getFullYear()+" "+pt.getMonth()); gives the result as 2019 11 What is the difference between using, and + in this example? 回答1: console.log(pt.getFullYear()," ",pt.getMonth()); The above example passes three separate arguments to console.log. What it outputs depends on how console.log is implemented. It has changed over time and is little bit different between browsers. When

Greater than operator given wrong response inside console.log in javascript

南笙酒味 提交于 2021-02-17 05:33:46
问题 I have tried conditional operator inside console.log() . Less than < returns correct response but greater than > returns wrong response. Why? console.log(5<6<7); //Output: true console.log(7>6>5); //output: false 回答1: The < operator accepts two operands and yields a boolean result. Your code is effectively: let temp = 7 > 6; console.log(temp); // true let result = temp > 5; console.log(result); // false The reason temp > 5 is false is that true > 5 coerces true to a number ( 1 ), and 1 > 5 is

Infinite console logging in React.js component

与世无争的帅哥 提交于 2021-02-10 23:30:27
问题 I'm working on my MERN app, and when I'm logging smth in NewsPage component, it logs infinitely. NewsPage component: const NewsPage = ({news, fetchNews}) => { const postNews = (title, body) => { axios.post("http://localhost:9000/news", { title, body }); } useEffect(() => { fetchNews(); }, [fetchNews, postNews]) return ( <> <AddNewsForm postNews={postNews}/> <h1>News:</h1> <NewsItemPage news={news} /> </> ); }; const mapStateToProps = state => ({ news: state.news }) export default connect

How to swap two elements inside of a 2D Array in JavaScript? (Confused about what I’m seeing from console.log in Chrome)

若如初见. 提交于 2021-02-08 20:53:20
问题 I want to swap two arrays inside a 2D array, however JS seems to be doing that before my actual swap is happening. This is for an algorithm I'm working on, providing each possible way to display a list of points. I have tried several ways of doing this, but the key problem keeps returning, and I've managed to crop it down to this peace of code: var points = [[1,2],[10,20],[100,200]]; console.log(points); var a = points[1][0]; var b = points[1][1]; points[1][0] = points[2][0]; points[1][1] =

How to swap two elements inside of a 2D Array in JavaScript? (Confused about what I’m seeing from console.log in Chrome)

拈花ヽ惹草 提交于 2021-02-08 20:51:11
问题 I want to swap two arrays inside a 2D array, however JS seems to be doing that before my actual swap is happening. This is for an algorithm I'm working on, providing each possible way to display a list of points. I have tried several ways of doing this, but the key problem keeps returning, and I've managed to crop it down to this peace of code: var points = [[1,2],[10,20],[100,200]]; console.log(points); var a = points[1][0]; var b = points[1][1]; points[1][0] = points[2][0]; points[1][1] =

How to get data from an object visible on browser console but returns null when I manually traverse it on my code?

孤人 提交于 2021-02-05 09:29:44
问题 //listen for messages channel.on("messageAdded", function (message) { //render new message console.log("New awesome message", message) //this is null for some reason console.log("Stringify 3",JSON.stringify(message.state.aggregatedDeliveryReceipt)) } But by storing it as a global object via console right click, I am able to do a console.log(temp1.state.aggregatedDeliveryReceipt) and get back The problem is that, when I use the same state.aggregatedDeliveryReceipt on my JS file, I am unable to

How to get data from an object visible on browser console but returns null when I manually traverse it on my code?

谁都会走 提交于 2021-02-05 09:29:16
问题 //listen for messages channel.on("messageAdded", function (message) { //render new message console.log("New awesome message", message) //this is null for some reason console.log("Stringify 3",JSON.stringify(message.state.aggregatedDeliveryReceipt)) } But by storing it as a global object via console right click, I am able to do a console.log(temp1.state.aggregatedDeliveryReceipt) and get back The problem is that, when I use the same state.aggregatedDeliveryReceipt on my JS file, I am unable to

Are DOM elements passed by reference to console.log? [duplicate]

别说谁变了你拦得住时间么 提交于 2021-01-27 14:11:21
问题 This question already has answers here : How can I make console.log show the current state of an object? (11 answers) Closed 6 years ago . I'm not even sure exactly what I'm asking here. I just know it isn't what I expected. I have a page script (see below) that grabs a reference to an element by its ID, then calls a few functions on it. Each function logs the element (or its textContent ) to the console, modifies the text contents, then calls the next function. What confuses me is how those

How to output each number consecutively in an index every second?

让人想犯罪 __ 提交于 2021-01-16 04:11:10
问题 I have the following loop: for (let index = 0; index < 4; index++) { setInterval(function() { console.log(index) }, 1000); } How can I make it so that it console logs 0 the first second, 1 the second second, 2 the third second, 3 the fourth second, 0 the fifth second, and so on until the interval is cleared? 回答1: Here's a more-or-less-but-rather-more elegant solution using a generator function. Generator functions are useful here, as their execution can be paused by yield , and resumed by

How to output each number consecutively in an index every second?

别来无恙 提交于 2021-01-16 04:11:07
问题 I have the following loop: for (let index = 0; index < 4; index++) { setInterval(function() { console.log(index) }, 1000); } How can I make it so that it console logs 0 the first second, 1 the second second, 2 the third second, 3 the fourth second, 0 the fifth second, and so on until the interval is cleared? 回答1: Here's a more-or-less-but-rather-more elegant solution using a generator function. Generator functions are useful here, as their execution can be paused by yield , and resumed by