DEV Community

Adam Crockett 🌀
Adam Crockett 🌀

Posted on

✒️ JavaScript syntax mini quiz

How many variable assignment keywords are there in JavaScript?

example: var

Please note this includes JavaScript from all of time.

Top comments (21)

Collapse
 
lazerfx profile image
Peter Street

var <varname> = - the classic.
let <varname> = - the modern.
const <varname> = - the unchanging
<varname> = - the 'oops I made this global by not actually using one'
window.<varname> = - the 'deliberate' global

At a guess, anyway... Been wracking my brains to back when I started with classic ASP and early JS in the likes of IE 6 and such, and this is all I can remember... but the brain's not what it used to be, so probably wrong :D

Collapse
 
paulooze profile image
Pavol Porubský

For clarification, <varname> = throws an error in 'strict mode' which means you can't use them inside type="module" scripts, as they are in strict mode by default (source: developer.mozilla.org/en-US/docs/W...).

Collapse
 
lazerfx profile image
Peter Street

Definitely - and that's one reason using 'strict' is a massively good thing to do :D Or, perhaps better, use TypeScript and benefit from a more deliberate variable declaration syntax.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Very nice, can you guess the bonus and deprecated variable from js 1.8?

Collapse
 
lazerfx profile image
Peter Street

Nope :D I never followed the language definition that far back, I have to admit - and Googling the MDN releases isn't very helpful.

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀
Thread Thread
 
lazerfx profile image
Peter Street

It's a shortcut for creating linked lists? I can see why it got deprecated. Looks like it was a mozilla only tooling...

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

I have no idea, I didn't stick around to find out. 😂

Collapse
 
omardev profile image
Sergio Omar Ajanel

var, let and const

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Incorrect. There are two more.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀 • Edited

Global and
Sharp variables (depreciated deprecated)

Thread Thread
 
mburszley profile image
Maximilian Burszley

Deprecated*. Depreciation is what happens when things lose value.

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

Same thing 😅, damn auto correct.

Collapse
 
paulooze profile image
Pavol Porubský

Which ones?

Collapse
 
vickyktk profile image
vickyktk

Var ,let & const

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Nope sorry read the comments for my cruel trick

Collapse
 
benaston profile image
Ben Aston • Edited

var is not an assignment keyword. If anything, it is a declaration keyword. If you want another way to declare a global variable (in a browser) simply add an id to a DOM node.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

I'm not sure I follow, can you elaborate on why var is not a means to assign a variable to a space in memory.

Also not sure how a html attributes is a variable unless it has some special relationship that other attributes do not?

Happy to learn new things, not trying to be annoying.

Collapse
 
codewilling profile image
Sean Flores

Does 'this.value = value' count as keyword variable assignment?

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Yes and no :) its a grey area.

Collapse
 
realinit profile image
realinit • Edited

var,let,const,global