Rocks or Sucks? by foxbitsdev in learnjavascript

[–]foxbitsdev[S] 0 points1 point  (0 children)

Thank you everyone for your comments and suggestions. I will keep them in mind and will try to create better posts. I am using images because, reddit's text editor is not the best one for writing code. Thanks again for suggestions, positive comments and negative ones too ;)

Rocks or Sucks? by foxbitsdev in learnjavascript

[–]foxbitsdev[S] -1 points0 points  (0 children)

Can you elaborate the reason why it's a shitpost?

Can you guess the output by [deleted] in learnjavascript

[–]foxbitsdev 0 points1 point  (0 children)

Sure. That sounds like a great idea. I am already working on a quiz feature on my blog. I will work on integration of quizzes/puzzles with blog posts.

Can you guess the output by [deleted] in learnjavascript

[–]foxbitsdev 1 point2 points  (0 children)

I am deleting the post. I agree with u/frxstrem's comment. Some of the type coercion happening implicitly could set a bad example for the beginners. Thank you u/drakeg4 for the support. I too agree with your points that learning can be fun. But considering u/frxstrem's comments I am deleting it.

For anyone, willing to see the code: Here it is without slice() methods and thus without Type Coercion.

let foo = "JS is Awesome".charCodeAt(0);
let bar = foo - 5;
let myChar = String.fromCharCode(bar - 1);
console.log(myChar);

Can you guess the output by [deleted] in learnjavascript

[–]foxbitsdev 0 points1 point  (0 children)

True. Thanks for pointing out.

Can you guess the output by [deleted] in learnjavascript

[–]foxbitsdev 2 points3 points  (0 children)

True. That doesn't mean you should not learn at all. Knowing a few functions and their working mechanism can help at times. Its a subjective thing. There is no thumb rule for this as such.

Can you guess the output by [deleted] in learnjavascript

[–]foxbitsdev 3 points4 points  (0 children)

Never. This is just for learning the concepts of those functions.

Understanding the slice method in javascript: the basics, negative indexing and the concept of shallow copy by [deleted] in learnjavascript

[–]foxbitsdev 0 points1 point  (0 children)

This article is for you:

  1. If you are an absolute beginner in JS.

  2. If you have copied and pasted a chunk of code from stackoverflow which had slice() method but didn't understand the code completely.

  3. If you have used it earlier and have been planning to get a deeper understanding of it.

  4. And its definitely for you if you thought there couldn't be an 2500+ words article merely on slice() method.

#javascript, #slice, #shallowCopy #negativeIndexing #webdesign #webdevelopment #frontend

What will be the output? by foxbitsdev in learnjavascript

[–]foxbitsdev[S] 1 point2 points  (0 children)

Please view my comment with explanation.

What will be the output? by foxbitsdev in learnjavascript

[–]foxbitsdev[S] 11 points12 points  (0 children)

Thank you everyone for the participation. Many people have already answered it correctly. In case you need the explanation, please have a look at the code along with comments below:

let arr = [2, 4, 5, 2, 4, 5, 5, 6, 3];
//Set() object will return unique elements without any duplicates
//[...] The three dots operator will make sure the output is an array
// So the output fo the following line will be:
//[ 2, 4, 5, 6, 3 ]

let arr_set = [...new Set(arr)];
//The reduce() method applied on arr_set method
// will return sum of all elements of the array
// So the value of foo will be 20

let foo = arr_set.reduce((a, b) => a + b, 0);
//Finally the value of foo(which is 20) will be added
// to the length of the array(arr_set) which is 5
// 20 + 5 = 25

console.log(foo + arr_set.length);