Skip to main content
Shortened code with given advice, gave a link explaining tilde in JavaScript.
Source Link
r2d2292
  • 103
  • 4

JavaScript (ES6), 5252 46 bytes

t=~~true;consolet=-~'';console.log(`${w=t+t++t}${f=tt-t}${w*w*w*w-wt/t}${t*t}`) 

Try it online!Try it online!

Will log through console.log the number 2014 as a string.

Thanks to Jacob for multiple optimizations saving 6 bytes

Explanation

t=~~true;t=-~''; 

In JavaScript,In JavaScript, ~~ will convert the proceeding value to a number, in this case, true equates to 1.

Set the value of ~~t will convert the proceeding value to a number, in this case, true1 equatesby using ~ on an empty string, which would equate to -1, then take the opposite of that number, 1.

For more info about tilde in JavaScript, see this article.

console.log(` ... `) 

Logs the template string ... with ${} expressions available, where ... includes:

${w=t+t++t} 

SetsSets w to t+t, which would be 2, which would return the number 2. Added to string.

Set wt to itself t+t+ 1, which would be 2, which would returnand display the numberfinal result, 2. Added to string.

${f=tt-t} 

Sets f toDisplays t-t, which would be 0 (false)0, which would return the number 0. Added to string

${t/t} 

Takes the value of t and divides by itself, returning 1.

${w*w*w*w-wt*t} 

Takes the value of w*w*w*w-w (or w ^ 4 - 1), where w (as previously set) is 2, and subtracts w from it, and returns the result. Added to string.

Takes the value of w*w*w*wt*t (or wt ^ 42), where wt (as previously set) is 2, and subtracts w from it, and returns the result. Added to string.

The added expressions equate to 2014, which ... is in the log.

JavaScript (ES6), 52 bytes

t=~~true;console.log(`${w=t+t}${f=t-t}${w*w*w*w-w}`) 

Try it online!

Will log through console.log the number 2014 as a string.

Explanation

t=~~true; 

In JavaScript, ~~ will convert the proceeding value to a number, in this case, true equates to 1.

console.log(` ... `) 

Logs the template string ... with ${} expressions available, where ... includes:

${w=t+t} 

Sets w to t+t, which would be 2, which would return the number 2. Added to string.

${f=t-t} 

Sets f to t-t, which would be 0 (false), which would return the number 0. Added to string.

${w*w*w*w-w} 

Takes the value of w*w*w*w (or w ^ 4), where w (as previously set) is 2, and subtracts w from it, and returns the result. Added to string.

The added expressions equate to 2014, which ... is in the log.

JavaScript (ES6), 52 46 bytes

t=-~'';console.log(`${++t}${t-t}${t/t}${t*t}`) 

Try it online!

Will log through console.log the number 2014 as a string.

Thanks to Jacob for multiple optimizations saving 6 bytes

Explanation

t=-~''; 

In JavaScript, ~~ will convert the proceeding value to a number, in this case, true equates to 1.

Set the value of t to 1 by using ~ on an empty string, which would equate to -1, then take the opposite of that number, 1.

For more info about tilde in JavaScript, see this article.

console.log(` ... `) 

Logs the template string ... with ${} expressions available, where ... includes:

${++t} 

Sets w to t+t, which would be 2, which would return the number 2. Added to string.

Set t to itself + 1, and display the final result, 2

${t-t} 

Displays t-t, which would be 0, which would return the number 0.

${t/t} 

Takes the value of t and divides by itself, returning 1.

${t*t} 

Takes the value of w*w*w*w-w (or w ^ 4 - 1), where w (as previously set) is 2, and subtracts w from it, and returns the result. Added to string.

Takes the value of t*t (or t ^ 2), where t (as previously set) is 2.

The added expressions equate to 2014, which ... is in the log.

Source Link
r2d2292
  • 103
  • 4

JavaScript (ES6), 52 bytes

t=~~true;console.log(`${w=t+t}${f=t-t}${w*w*w*w-w}`) 

Try it online!

Will log through console.log the number 2014 as a string.

Explanation

t=~~true; 

In JavaScript, ~~ will convert the proceeding value to a number, in this case, true equates to 1.

console.log(` ... `) 

Logs the template string ... with ${} expressions available, where ... includes:

${w=t+t} 

Sets w to t+t, which would be 2, which would return the number 2. Added to string.

${f=t-t} 

Sets f to t-t, which would be 0 (false), which would return the number 0. Added to string.

${w*w*w*w-w} 

Takes the value of w*w*w*w (or w ^ 4), where w (as previously set) is 2, and subtracts w from it, and returns the result. Added to string.

The added expressions equate to 2014, which ... is in the log.