PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 9, 2022

[FIXED] Why can I define something as 'let'?

 July 09, 2022     javascript, keyword, let     No comments   

Issue

I was experimenting with JS and jokingly tried to redefine let keyword and surprisingly it worked.

It does not work with any other keywords like while,const,var etc. Any reason why JS is working fine with this?

let = 'Weird'
console.log(let)
console.log(typeof let)
console.log(let.length)

let = ['Weird','Very Weird']
console.log(let)
console.log(typeof let)
console.log(let.length)

let = 80
console.log(let)
console.log(typeof let)
console.log(let/80)

Also another weird thing:

var let = 'Even More Weird'
console.log(let)
let = 50
console.log(let)
let = (x)=>x**2
console.log(let(3))


Solution

you can redeclare let if you don't specify strict mode by :

"use strict"; // firt statement on the script
...

it depends also in the engine that execute the code, in firefox(spiderMonkey engine) engine you would see an error : "Uncaught SyntaxError: redeclaration of let i", but in V8 in chrome if you don't specify a strict mode, it would work without problem



Answered By - Mohamed BEN KHOUYA
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing