javascript-coding-practice
Repo learning-zone/javascript-coding-practice, read from GitHub 1 min ago. learning-zone has not joined Take My Repo.
learning-zone/javascript-coding-practice is a public repo on GitHub by learning-zone. javascript-coding-practice. It declares the MIT license on GitHub. It is written mainly in JavaScript, has 107 stars and last changed on 2023-01-28. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-18.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Click ★ if you like the project. Your contributions are heartily ♡ welcome.
var g = 0; g = 1 && g++; console.log(g);
console.log(employeeId); var employeeId = "19000";
undefined
ReferenceError: employeeId is not defined
var a = 1.2; console.log(typeof a);
const a = { msg: "Hi" }; const b = a; b.msg = "Hello"; console.log(a, b);
{ msg: 'Hello' } { msg: 'Hello' }
let text = "hello"; let text = "hello world"; console.log(text);
SyntaxError: Identifier 'text' has already been declared
const text = "Hi"; text = "Hello"; console.log(text);
TypeError: Assignment to constant variable.
console.log('The value of num is: ' + num);
ReferenceError: num is not defined
console.log(num); const num = 10;
ReferenceError: Cannot access 'num' before initialization
var num = 8; var num = 10; console.log(num);
With the var keyword, you can declare multiple variables with the same name. The variable will then hold the latest value.
You cannot do this with let or const since they're block-scoped.
(() => { let x = (y = 10); })(); console.log(typeof x); console.log(typeof y);
let x = y = 10; is actually shorthand for:
y = 10; let x = y;
When we set y equal to 10, we actually add a property y to the global object (window in browser, global in Node). In a browser, window.y is now equal to 10.
Then, we declare a variable x with the value of y, which is 10. Variables declared with the let keyword are block scoped, they are only defined within the block they're declared in; the immediately-invoked function (IIFE) in this case. When we use the typeof operator, the operand x is not defined: we are trying to access x outside of the block it's declared in. This means that x is not defined. Values who haven't been assigned a value or declared are of type "undefined". console.log(typeof x) returns "undefined".
However, we created a global variable y when setting y equal to 10. This value is accessible anywhere in our code. y is defined, and holds a value of type "number". console.log(typeof y) returns "number".
const name = "Swarna"; age = 21; console.log(delete name); console.log(delete age);
The delete operator returns a boolean value: true on a successful deletion, else it'll return false. However, variables declared with the var, const or let keyword cannot be deleted using the delete operator.
The name variable was declared with a const keyword, so its deletion is not successful: false is returned. When we set age equal to 21, we actually added a property called age to the global object. You can successfully delete properties from objects this way, also the global object, so delete age returns true.
const name = "Akhil Sunder"; console.log(name.padStart(13)); console.log(name.padStart(2));
With the padStart method, we can add padding to the beginning of a string. The value passed to this method is the total length of the string together with the padding. The string "Akhil Sunder" has a length of 12. name.padStart(13) inserts 1 space at the start of the string, because 12 + 1 is 13.
If the argument passed to the padStart method is smaller than the length of the array, no padding will be added.
console.log(String.raw`Hello\nworld`);
String.raw returns a string where the escapes (\n, \v, \t etc.) are ignored! Backslashes can be an issue since you could end up with something like:
const path = `C:\Documents\Projects\table.html`
Which would result in:
"C:DocumentsProjects able.html"
With String.raw, it would simply ignore the escape and print:
C:\Documents\Projects\table.html
In this case, the string is Hello\nworld, which gets logged.
const { name: myName } = { name: "Anusha Kapadia" }; console.log(name);
When we unpack the property name from the object on the right-hand side, we assign its value "Anusha Kapadia" to a variable with the name myName.
With { name: myName }, we tell JavaScript that we want to create a new variable called myName with the value of the name property on the right-hand side.
Since we try to log name, a variable that is not defined, a ReferenceError gets thrown.
const name = "Anima Nagarajan"; console.log(name());
The variable name holds the value of a string, which is not a function, thus cannot invoke.
TypeErrors get thrown when a value is not of the expected type. JavaScript expected name to be a function since we're trying to invoke it. It was a string however, so a TypeError gets thrown: name is not a function!
SyntaxErrors get thrown when you've written something that isn't valid JavaScript, for example when you've written the word return as retrun.
ReferenceErrors get thrown when JavaScript isn't able to find a reference to a value that you're trying to access.
const num = 10; console.log(Num);
ReferenceError: Num is not defined
console.log(isNaN(true));
falseconsole.log(0.1 + 0.2 == 0.3);
console.log(false == "0"); console.log(false === "0");
console.log(0.1 + 0.2); console.log(0.1 + 0.2 == 0.3);
var x = 10; if (x) { let x = 4; } console.log(x);
const numOne = 2; const numTwo = 3; const res = numOne ** numTwo; console.log(res);
In the code below we calculate numOne to the power of numTwo with the Exponential operator **. Then, the console.log() statement checks whether the result of this calculation equals 8. Change the code so that the console.log() statement logs true.
8let number = 0; console.log(number++); console.log(++number); console.log(number);
The postfix unary operator ++:
0)1)The prefix unary operator ++:
2)2)This returns 0 2 2.
let num = 10; const increaseNumber = () => num++; const increasePassedNumber = (number) => number++; const num1 = increaseNumber(); const num2 = increasePassedNumber(num1); console.log(num1); console.log(num2);
The unary operator ++ first returns the value of the operand, then increments the value of the operand. The value of num1 is 10, since the increaseNumber function first returns the value of num, which is 10, and only increments the value of num afterwards.
num2 is 10, since we passed num1 to the increasePassedNumber. number is equal to 10(the value of num1. Again, the unary operator ++ first returns the value of the operand, then increments the value of the operand. The value of number is 10, so num2 is equal to 10.
+true; !"Mala Pall";
The unary plus tries to convert an operand to a number. true is 1, and false is 0.
The string 'Mala Pall' is a truthy value. What we're actually asking, is "is this truthy value falsy?". This returns false.
let a = 3; let b = new Number(3); let c = 3; console.log(a == b); console.log(a === b); console.log(b === c);
new Number() is a built-in function constructor. Although it looks like a number, it's not really a number: it has a bunch of extra features and is an object.
When we use the == operator, it only checks whether it has the same value. They both have the value of 3, so it returns true.
However, when we use the === operator, both value and type should be the same. It's not: new Number() is not a number, it's an object. Both return false.
0; new Number(0); (""); (" "); new Boolean(false); undefined;
There are only six falsy values:
undefinednullNaN0'' (empty string)falseFunction constructors, like new Number and new Boolean are truthy.
console.log(typeof typeof 1);
`typeof 1` returns `"number"`. `typeof "number"` returns `"string"`
!!null; !!""; !!1;
null is falsy. !null returns true. !true returns false.
"" is falsy. !"" returns true. !true returns false.
1 is truthy. !1 returns false. !false returns true.
const info = { [Symbol("a")]: "b", }; console.log(info); console.log(Object.keys(info));
A Symbol is not enumerable. The Object.keys method returns all enumerable key properties on an object. The Symbol won't be visible, and an empty array is returned. When logging the entire object, all properties will be visible, even non-enumerable ones.
This is one of the many qualities of a symbol: besides representing an entirely unique value (which prevents accidental name collision on objects, for example when working with 2 libraries that want to add properties to the same object), you can also "hide" properties on objects this way (although not entirely. You can still access symbols using the Object.getOwnPropertySymbols() method).
const one = false || {} || null; const two = null || false || ""; const three = [] || 0 || true; console.log(one, two, three);
With the || operator, we can return the first truthy operand. If all values are falsy, the last operand gets returned.
(false || {} || null): the empty object {} is a truthy value. This is the first (and only) truthy value, which gets returned. one is equal to {}.
(null || false || ""): all operands are falsy values. This means that the past operand, "" gets returned. two is equal to "".
([] || 0 || ""): the empty array[] is a truthy value. This is the first truthy value, which gets returned. three is equal to [].
const output = `${[] && "Im"}possible! You should${"" && `n't`} see a therapist after so much JavaScript lol`;
[] is a truthy value. With the && operator, the right-hand value will be returned if the left-hand value is a truthy value. In this case, the left-hand value [] is a truthy value, so "Im' gets returned.
"" is a falsy value. If the left-hand value is falsy, nothing gets returned. n\'t doesn't get returned.
console.log(`${((x) => x)("I love")} to program`);
Expressions within template literals are evaluated first. This means that the string will contain the returned value of the expression, the immediately invoked function (x => x)('I love') in this case. We pass the value 'I love' as an argument to the x => x arrow function. x is equal to 'I love', which gets returned. This results in I love to program.
if(2 == true) if(2 == false)
SyntaxError: Unexpected end of input
const length = 4; const numbers = []; for (var i = 0; i < length; i++); { numbers.push(i + 1); } console.log(numbers);
[ 5 ]
num?const num = parseInt("7*6", 10);
Only the first numbers in the string is returned. Based on the radix (the second argument in order to specify what type of number we want to parse it to: base 10, hexadecimal, octal, binary, etc.), the parseInt checks whether the characters in the string are valid. Once it encounters a character that isn't a valid number in the radix, it stops parsing and ignores the following characters.
* is not a valid number. It only parses "7" into the decimal 7. num now holds the value of 7.
console.log(Number(2) === Number(2)); console.log(Boolean(false) === Boolean(false)); console.log(Symbol("foo") === Symbol("foo"));
Every Symbol is entirely unique. The purpose of the argument passed to the Symbol is to give the Symbol a description. The value of the Symbol is not dependent on the passed argument. As we test equality, we are creating two entirely new symbols: the first Symbol('foo'), and the second Symbol('foo'). These two values are unique and not equal to each other, Symbol('foo') === Symbol('foo') returns false.
console.log(1 + -"1" + 2);
var result; for (var i = 5; i > 0; i--) { result = result + i; } console.log(result);
console.log(+"Hello");
console.log(eval("10 + 10")); console.log(eval("5 + 5" + 10)); console.log(eval("5 + 5 + 5" + 10)); console.log(eval(10 + "5 + 5")); console.log(eval(10 + "5 + 5 + 5"));
var x = 10; var y = 20; var a = eval("x * y") + "<br>"; var b = eval("2 + 2") + "<br>"; var c = eval("x + 30") + "<br>"; let result = a + b + c; console.log(result);
sum?const sum = eval("10*10+5");
eval evaluates codes that's passed as a string. If it's an expression, like in this case, it evaluates the expression. The expression is 10 * 10 + 5. This returns the number 105.
foo?var foo = 10 + "20";
'1020', because of type coercion from Number to String
The output is going to be 33. Since 1 and 2 are numeric values, the result of first two digits is going to be a numeric value 3. The next digit is a string type value because of that the addition of numeric value 3 and string type value 3 is just going to be a concatenation value 33.
"i'm a lasagna hog".split("").reverse().join("");
It's actually a reverse method for a string - 'goh angasal a m\'i'
foo?var foo = 10 + "20";
'1020', because of type coercion from Number to String
var strA = "hi there"; var strB = strA; strB = "bye there!"; console.log(strA);
The output will 'hi there' because we're dealing with strings here. Strings are
passed by value, that is, copied.
console.log(3 + 4 + "5");
Operator associativity is the order in which the compiler evaluates the expressions, either left-to-right or right-to-left. This only happens if all operators have the same precedence. We only have one type of operator: +. For addition, the associativity is left-to-right.
3 + 4 gets evaluated first. This results in the number 7.
7 + '5' results in "75" because of coercion. JavaScript converts the number 7 into a string, see question 15. We can concatenate two strings using the +operator. "7" + "5" results in "75".
let a = "7" + 3 + 2; let b = 7 + 3 + "2"; console.log(a, b);
732 102
console.log(typeof [1, [2, [3, [4, [5, 6]]]]][0]);
number[..."Inika "];
A string is an iterable. The spread operator maps every character of an iterable to one element.
const numbers = [1, 2, 3, 4, 5]; const [y] = numbers; console.log(y);
We can unpack values from arrays or properties from objects through destructuring. For example:
[a, b] = [1, 2];
The value of a is now 1, and the value of b is now 2. What we actually did in the question, is:
[y] = [1, 2, 3, 4, 5];
This means that the value of y is equal to the first value in the array, which is the number 1. When we log y, 1 is returned.
const list = [1 + 2, 1 * 2, 1 / 2]; console.log(list);
Array elements can hold any value. Numbers, strings, objects, other arrays, null, boolean values, undefined, and other expressions such as dates, functions, and calculations.
The element will be equal to the returned value. 1 + 2 returns 3, 1 * 2 returns 2, and 1 / 2 returns 0.5.
[ [0, 1], [2, 3], ].reduce( (acc, cur) => { return acc.concat(cur); }, [1, 2] );
[1, 2] is our initial value. This is the value we start with, and the value of the very first acc. During the first round, acc is [1,2], and cur is [0, 1]. We concatenate them, which results in [1, 2, 0, 1].
Then, [1, 2, 0, 1] is acc and [2, 3] is cur. We concatenate them, and get [1, 2, 0, 1, 2, 3]
const numbers = [1, 2, 3]; numbers[10] = 11; console.log(numbers);
When you set a value to an element in an array that exceeds the length of the array, JavaScript creates something called "empty slots". These actually have the value of undefined, but you will see something like:
[1, 2, 3, 7 x empty, 11]
depending on where you run it (it's different for every browser, node, etc.)
foo.length?var foo = []; foo.push(1); foo.push(2);
.push is mutable - 2
(function () { var greet = "Hello World"; var toGreet = [].filter.call(greet, function (element, index) { return index > 5; }); console.log(toGreet); })();
[ 'W', 'o', 'r', 'l', 'd' ]
(function () { var arrayNumb = [2, 8, 15, 16, 23, 42]; arrayNumb.sort(); console.log(arrayNumb); })();
[ 15, 16, 2, 23, 42, 8 ]
(function () { var list = ["foo", "bar", "john"]; console.log(list.splice(1)); console.log(list.splice(1, 2)); console.log(list); })();
[ 'bar', 'john' ] [] [ 'foo' ]
(function () { var list = ["foo", "bar", "john", "ritz"]; console.log(list.slice(1)); console.log(list.slice(1, 3)); console.log(list.slice()); console.log(list.slice(2, 2)); console.log(list); })();
[ 'bar', 'john', 'ritz' ] [ 'bar', 'john' ] [ 'foo', 'bar', 'john', 'ritz' ] [] [ 'foo', 'bar', 'john', 'ritz' ]
(function () { var containers = [2, 0, false, "", "12", true]; var containers = containers.filter(Boolean); console.log(containers); var containers = containers.filter(Number); console.log(containers); var containers = containers.filter(String); console.log(containers); var containers = containers.filter(Object); console.log(containers); })();
[ 2, '12', true ] [ 2, '12', true ] [ 2, '12', true ] [ 2, '12', true ]
(function () { var numbers = [2, 3, 4, 8, 9, 11, 13, 12, 16]; var even = numbers.filter(function (element, index) { return element % 2 === 0; }); console.log(even); var containsDivisibleby3 = numbers.some(function (element, index) { return element % 3 === 0; }); console.log(containsDivisibleby3); })();
[ 2, 4, 8, 12, 16 ] true
(function () { var array = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6]; console.log(array.indexOf(2)); console.log(array.indexOf(2, 3)); console.log(array.indexOf(2, 10)); })();
1 6 -1
(function () { var animal = ["cow", "horse"]; animal.push("cat"); animal.unshift("dog", "rat", "goat"); console.log(animal); })();
[ 'dog', 'rat', 'goat', 'cow', 'horse', 'cat' ]
(function () { var array = [1, 2, 3, 4, 5]; console.log(array.indexOf(2)); console.log([{ name: "John" }, { name: "John" }].indexOf({ name: "John" })); console.log([[1], [2], [3], [4]].indexOf([3])); console.log("abcdefgh".indexOf("e")); })();
(function () { var animal = ["cow", "horse"]; animal.push("cat"); animal.push("dog", "rat", "goat"); console.log(animal.length); })();
6(function () { var array = new Array("a", "b", "c", "d", "e"); array[10] = "f"; delete array[10]; console.log(array.length); })();
11(function () { var array1 = []; var array2 = new Array(100); var array3 = new Array(["1", 2, "3", 4, 5.6]); console.log(array1); console.log(array2); console.log(array3); console.log(array3.length); })();
[] [] [Array[5]] 1
(function () { var array = new Array("100"); console.log(array); console.log(array.length); })();
["100"] 1
var arrA = [ { prop1: "value of array A!!" }, { someProp: "also value of array A!" }, 3, 4, 5, ]; var arrB = arrA.slice(); arrB[0].prop1 = 42; arrB[3] = 20; console.log(arrA);
The output will be [{prop1: 42}, {someProp: "also value of array A!"}, 3,4,5].
The slice function copies all the elements of the array returning the new array. However,
it doesn't do deep copying. Instead it does shallow copying. You can imagine slice implemented like this:
function slice(arr) { var result = []; for (i = 0; i < arr.length; i++) { result.push(arr[i]); } return result; }
Look at the line with result.push(arr[i]). If arr[i] happens to be a number or string,
it will be passed by value, in other words, copied. If arr[i] is an object, it will be passed by reference.
In case of our array arr[0] is an object {prop1: "value of array A!!"}. Only the reference
to this object will be copied. This effectively means that arrays arrA and arrB share first
two elements.
This is why changing the property of arrB[0] in arrB will also change the arrA[0].
var arrA = [ { prop1: "value of array A!!" }, { someProp: "also value of array A!" }, 3, 4, 5, ]; var arrB = arrA; arrB[0].prop1 = 42; console.log(arrA);
The output will be [{prop1: 42}, {someProp: "also value of array A!"}, 3,4,5].
Arrays are object in JS, so both varaibles arrA and arrB point to the same array. Changing
arrB[0] is the same as changing arrA[0]
var arrA = [0, 1, 2, 3, 4, 5]; var arrB = arrA.slice(); arrB[0] = 42; console.log(arrA);
The output will be [0,1,2,3,4,5].
The slice function copies all the elements of the array returning the new array. That's why
arrA and arrB reference two completely different arrays.
var arrA = [0, 1, 2, 3, 4, 5]; var arrB = arrA; arrB[0] = 42; console.log(arrA);
The output will be [42,1,2,3,4,5].
Arrays are object in JavaScript and they are passed and assigned by reference. This is why
both arrA and arrB point to the same array [0,1,2,3,4,5]. That's why changing the first
element of the arrB will also modify arrA: it's the same array in the memory.
var trees = ["xyz", "xxxx", "test", "ryan", "apple"]; delete trees[3]; console.log(trees.length);
The code above will output 5 as output. When we used delete operator for deleting an array element then, the array length is not affected by this. This holds even if you deleted all elements of an array using delete operator.
So when delete operator removes an array element that deleted element is no longer present in the array. In place of value at deleted index undefined x 1 in chrome and undefined is placed at the index. If you do console.log(trees) output ["xyz", "xxxx", "test", undefined × 1, "apple"] in Chrome and in Firefox ["xyz", "xxxx", "test", undefined, "apple"].
var arr = ["javascript", "typescript", "es6"]; var searchValue = (value) => { return arr.filter((item) => { return item.indexOf(value) > -1; }); }; console.log(searchValue("script"));
const arr = [1, 2]; arr.push(3);
const arr = [10, 20, 30]; arr.push(40); console.log(arr) const arr1 = [10, 20, 30]; arr1 = []; console.log(arr1) const arr2 = [10, 20, 30]; arr2[2] = 50; console.
learning-zone/javascript-coding-practice is a public repo on GitHub by learning-zone. javascript-coding-practice.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2023-01-28. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Node.js Basics ( v24.x )